@@ -4,68 +4,56 @@ import { sentryTest } from '../../../utils/fixtures';
4
4
import { getExpectedReplayEvent } from '../../../utils/replayEventTemplates' ;
5
5
import { getReplayEvent , shouldSkipReplayTest , waitForReplayRequest } from '../../../utils/replayHelpers' ;
6
6
7
- // Sync this with init.js - not we take seconds here instead of ms
8
- const FLUSH_DELAY_SECONDS = 0.5 ;
9
-
10
- for ( let index = 0 ; index < 25 ; index ++ ) {
11
- sentryTest ( `replay recording flushes every FLUSH_DELAY_SECONDS ( ${ index } )}` , async ( { getLocalTestPath , page } ) => {
12
- if ( shouldSkipReplayTest ( ) ) {
13
- sentryTest . skip ( ) ;
14
- }
15
-
16
- const reqPromise0 = waitForReplayRequest ( page , 0 ) ;
17
- const reqPromise1 = waitForReplayRequest ( page , 1 ) ;
18
- const reqPromise2 = waitForReplayRequest ( page , 2 ) ;
19
-
20
- await page . route ( 'https://dsn.ingest.sentry.io/**/*' , route => {
21
- return route . fulfill ( {
22
- status : 200 ,
23
- contentType : 'application/json' ,
24
- body : JSON . stringify ( { id : 'test-id' } ) ,
7
+ for ( let index = 0 ; index < 50 ; index ++ ) {
8
+ sentryTest (
9
+ `replay events are flushed after max flash delay was reached ( ${ index } )` ,
10
+ async ( { getLocalTestPath , page } ) => {
11
+ if ( shouldSkipReplayTest ( ) ) {
12
+ sentryTest . skip ( ) ;
13
+ }
14
+
15
+ const reqPromise0 = waitForReplayRequest ( page , 0 ) ;
16
+ const reqPromise1 = waitForReplayRequest ( page , 1 ) ;
17
+ const reqPromise2 = waitForReplayRequest ( page , 2 ) ;
18
+
19
+ await page . route ( 'https://dsn.ingest.sentry.io/**/*' , route => {
20
+ return route . fulfill ( {
21
+ status : 200 ,
22
+ contentType : 'application/json' ,
23
+ body : JSON . stringify ( { id : 'test-id' } ) ,
24
+ } ) ;
25
25
} ) ;
26
- } ) ;
27
-
28
- const url = await getLocalTestPath ( { testDir : __dirname } ) ;
29
-
30
- await page . goto ( url ) ;
31
- const replayEvent0 = getReplayEvent ( await reqPromise0 ) ;
32
- expect ( replayEvent0 ) . toEqual ( getExpectedReplayEvent ( ) ) ;
33
-
34
- // trigger mouse click
35
- void page . click ( '#go-background' ) ;
36
-
37
- const replayEvent1 = getReplayEvent ( await reqPromise1 ) ;
38
- expect ( replayEvent1 ) . toEqual (
39
- getExpectedReplayEvent ( { replay_start_timestamp : undefined , segment_id : 1 , urls : [ ] } ) ,
40
- ) ;
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 ( '#go-background' ) ;
47
- } catch {
48
- // ignore errors here, we don't care if the page is closed
49
- }
50
- } , i * 100 ) ;
51
- }
52
-
53
- const replayEvent2 = getReplayEvent ( await reqPromise2 ) ;
54
- expect ( replayEvent2 ) . toEqual (
55
- getExpectedReplayEvent ( { replay_start_timestamp : undefined , segment_id : 2 , urls : [ ] } ) ,
56
- ) ;
57
-
58
- // Ensure time diff is about 500ms between each event
59
- const diff1 = replayEvent1 . timestamp ! - replayEvent0 . timestamp ! ;
60
- const diff2 = replayEvent2 . timestamp ! - replayEvent1 . timestamp ! ;
61
26
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 ) ;
70
- } ) ;
27
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
28
+
29
+ await page . goto ( url ) ;
30
+ const replayEvent0 = getReplayEvent ( await reqPromise0 ) ;
31
+ expect ( replayEvent0 ) . toEqual ( getExpectedReplayEvent ( ) ) ;
32
+
33
+ // trigger one mouse click
34
+ void page . click ( '#something' ) ;
35
+
36
+ // this must eventually lead to a flush after the max delay was reached
37
+ const replayEvent1 = getReplayEvent ( await reqPromise1 ) ;
38
+ expect ( replayEvent1 ) . toEqual (
39
+ getExpectedReplayEvent ( { replay_start_timestamp : undefined , segment_id : 1 , urls : [ ] } ) ,
40
+ ) ;
41
+
42
+ // trigger mouse click every 100ms, it should still flush after the max delay even if clicks are ongoing
43
+ for ( let i = 0 ; i < 700 ; 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
+
53
+ const replayEvent2 = getReplayEvent ( await reqPromise2 ) ;
54
+ expect ( replayEvent2 ) . toEqual (
55
+ getExpectedReplayEvent ( { replay_start_timestamp : undefined , segment_id : 2 , urls : [ ] } ) ,
56
+ ) ;
57
+ } ,
58
+ ) ;
71
59
}
0 commit comments