@@ -32,24 +32,23 @@ for (let index = 0; index < 25; index++) {
3232 expect ( replayEvent0 ) . toEqual ( getExpectedReplayEvent ( ) ) ;
3333
3434 // trigger mouse click
35- void page . click ( '#something ' ) ;
35+ void page . click ( '#go-background ' ) ;
3636
3737 const replayEvent1 = getReplayEvent ( await reqPromise1 ) ;
3838 expect ( replayEvent1 ) . toEqual (
3939 getExpectedReplayEvent ( { replay_start_timestamp : undefined , segment_id : 1 , urls : [ ] } ) ,
4040 ) ;
4141
42- // // trigger mouse click every 100ms, it should still flush after 0.5s even if clicks are ongoing
43- // for (let i = 0; i < 70; i++) {
44- // setTimeout(async () => {
45- // try {
46- // await page.click('#something');
47- // } catch {
48- // // ignore errors here, we don't care if the page is closed
49- // }
50- // }, i * 100);
51- // }
52- await page . click ( '#something' ) ;
42+ // trigger mouse click every 100ms, it should still flush after 0.5s even if clicks are ongoing
43+ for ( let i = 0 ; i < 70 ; i ++ ) {
44+ setTimeout ( async ( ) => {
45+ try {
46+ await page . click ( '#go-background' ) ;
47+ } catch {
48+ // ignore errors here, we don't care if the page is closed
49+ }
50+ } , i * 100 ) ;
51+ }
5352
5453 const replayEvent2 = getReplayEvent ( await reqPromise2 ) ;
5554 expect ( replayEvent2 ) . toEqual (
@@ -60,10 +59,13 @@ for (let index = 0; index < 25; index++) {
6059 const diff1 = replayEvent1 . timestamp ! - replayEvent0 . timestamp ! ;
6160 const diff2 = replayEvent2 . timestamp ! - replayEvent1 . timestamp ! ;
6261
63- // We want to check that the diff is between 0.05 and 0.95 seconds, to accomodate for some wiggle room
64- expect ( diff1 ) . toBeLessThan ( FLUSH_DELAY_SECONDS + 0.45 ) ;
65- expect ( diff1 ) . toBeGreaterThanOrEqual ( FLUSH_DELAY_SECONDS - 0.45 ) ;
66- expect ( diff2 ) . toBeLessThan ( FLUSH_DELAY_SECONDS + 0.45 ) ;
67- expect ( diff2 ) . toBeGreaterThanOrEqual ( FLUSH_DELAY_SECONDS - 0.45 ) ;
62+ // Playwright is very inconsistent with timing, so we have to ease up the expectations a lot here.
63+ // Generally, we'd expect to see a diff of FLUSH_DELAY_SECONDS, but we've observed test flakes up to 2.5s.
64+ // The beste we can do here is ensure that the flushes actually happen in a somewhat reasonable time frame within
65+ // one order of magnitude of FLUSH_DELAY_SECONDS.
66+ expect ( diff1 ) . toBeLessThan ( FLUSH_DELAY_SECONDS * 10 ) ;
67+ expect ( diff1 ) . toBeGreaterThanOrEqual ( FLUSH_DELAY_SECONDS - 0.4 ) ;
68+ expect ( diff2 ) . toBeLessThan ( FLUSH_DELAY_SECONDS * 10 ) ;
69+ expect ( diff2 ) . toBeGreaterThanOrEqual ( FLUSH_DELAY_SECONDS - 0.4 ) ;
6870 } ) ;
6971}
0 commit comments