@@ -4,10 +4,15 @@ import { sentryTest } from '../../../utils/fixtures';
44import { getExpectedReplayEvent } from '../../../utils/replayEventTemplates' ;
55import { getReplayEvent , shouldSkipReplayTest , waitForReplayRequest } from '../../../utils/replayHelpers' ;
66
7- // Sync this with init.js - not we take seconds here instead of ms
8- const FLUSH_DELAY_SECONDS = 0.5 ;
9-
10- sentryTest ( 'replay recording flushes every 5s' , async ( { getLocalTestPath, page } ) => {
7+ /*
8+ * In this test we're explicitly not forcing a flush by triggering a visibility change.
9+ * Instead, we want to verify that the `flushMaxDelay` works in the sense that eventually
10+ * a flush is triggered if some events are in the buffer.
11+ * Note: Due to timing problems and inconsistencies in Playwright/CI, we can't reliably
12+ * assert on the flush timestamps. Therefore we only assert that events were eventually
13+ * sent (i.e. flushed).
14+ */
15+ sentryTest ( 'replay events are flushed after max flush delay was reached' , async ( { getLocalTestPath, page } ) => {
1116 if ( shouldSkipReplayTest ( ) ) {
1217 sentryTest . skip ( ) ;
1318 }
@@ -30,17 +35,18 @@ sentryTest('replay recording flushes every 5s', async ({ getLocalTestPath, page
3035 const replayEvent0 = getReplayEvent ( await reqPromise0 ) ;
3136 expect ( replayEvent0 ) . toEqual ( getExpectedReplayEvent ( ) ) ;
3237
33- // trigger mouse click
34- void page . click ( '#go-background ' ) ;
38+ // trigger one mouse click
39+ void page . click ( '#something ' ) ;
3540
41+ // this must eventually lead to a flush after the max delay was reached
3642 const replayEvent1 = getReplayEvent ( await reqPromise1 ) ;
3743 expect ( replayEvent1 ) . toEqual ( getExpectedReplayEvent ( { replay_start_timestamp : undefined , segment_id : 1 , urls : [ ] } ) ) ;
3844
39- // trigger mouse click every 100ms, it should still flush after 5s even if clicks are ongoing
40- for ( let i = 0 ; i < 70 ; i ++ ) {
45+ // trigger mouse click every 100ms, it should still flush after the max delay even if clicks are ongoing
46+ for ( let i = 0 ; i < 700 ; i ++ ) {
4147 setTimeout ( async ( ) => {
4248 try {
43- await page . click ( '#go-background ' ) ;
49+ await page . click ( '#something ' ) ;
4450 } catch {
4551 // ignore errors here, we don't care if the page is closed
4652 }
@@ -49,14 +55,4 @@ sentryTest('replay recording flushes every 5s', async ({ getLocalTestPath, page
4955
5056 const replayEvent2 = getReplayEvent ( await reqPromise2 ) ;
5157 expect ( replayEvent2 ) . toEqual ( getExpectedReplayEvent ( { replay_start_timestamp : undefined , segment_id : 2 , urls : [ ] } ) ) ;
52-
53- // Ensure time diff is about 500ms between each event
54- const diff1 = replayEvent1 . timestamp ! - replayEvent0 . timestamp ! ;
55- const diff2 = replayEvent2 . timestamp ! - replayEvent1 . timestamp ! ;
56-
57- // We want to check that the diff is between 0.1 and 0.9 seconds, to accomodate for some wiggle room
58- expect ( diff1 ) . toBeLessThan ( FLUSH_DELAY_SECONDS + 0.4 ) ;
59- expect ( diff1 ) . toBeGreaterThanOrEqual ( FLUSH_DELAY_SECONDS - 0.4 ) ;
60- expect ( diff2 ) . toBeLessThan ( FLUSH_DELAY_SECONDS + 0.4 ) ;
61- expect ( diff2 ) . toBeGreaterThanOrEqual ( FLUSH_DELAY_SECONDS - 0.4 ) ;
6258} ) ;
0 commit comments