@@ -32,24 +32,23 @@ for (let index = 0; index < 25; index++) {
32
32
expect ( replayEvent0 ) . toEqual ( getExpectedReplayEvent ( ) ) ;
33
33
34
34
// trigger mouse click
35
- void page . click ( '#something ' ) ;
35
+ void page . click ( '#go-background ' ) ;
36
36
37
37
const replayEvent1 = getReplayEvent ( await reqPromise1 ) ;
38
38
expect ( replayEvent1 ) . toEqual (
39
39
getExpectedReplayEvent ( { replay_start_timestamp : undefined , segment_id : 1 , urls : [ ] } ) ,
40
40
) ;
41
41
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
+ }
53
52
54
53
const replayEvent2 = getReplayEvent ( await reqPromise2 ) ;
55
54
expect ( replayEvent2 ) . toEqual (
@@ -60,10 +59,13 @@ for (let index = 0; index < 25; index++) {
60
59
const diff1 = replayEvent1 . timestamp ! - replayEvent0 . timestamp ! ;
61
60
const diff2 = replayEvent2 . timestamp ! - replayEvent1 . timestamp ! ;
62
61
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 ) ;
68
70
} ) ;
69
71
}
0 commit comments