@@ -19,7 +19,7 @@ const SESSION_MAX_AGE = 4000;
19
19
The main difference between this and sessionExpiry test, is that here we wait for the overall time (4s)
20
20
in multiple steps (2s, 2s) instead of waiting for the whole time at once (4s).
21
21
*/
22
- for ( let i = 0 ; i < 1 ; i ++ ) {
22
+ for ( let i = 0 ; i < 100 ; i ++ ) {
23
23
sentryTest ( `handles session that exceeds max age RUN ${ i } ` , async ( { getLocalTestPath, page } ) => {
24
24
if ( shouldSkipReplayTest ( ) ) {
25
25
sentryTest . skip ( ) ;
@@ -39,8 +39,13 @@ for (let i = 0; i < 1; i++) {
39
39
const url = await getLocalTestPath ( { testDir : __dirname } ) ;
40
40
41
41
await page . goto ( url ) ;
42
+
43
+ const replay0 = await getReplaySnapshot ( page ) ;
44
+ // We use the `initialTimestamp` of the replay to do any time based calculations
45
+ // @ts -ignore this is fine
46
+ const startTimestamp = replay0 . _context . initialTimestamp ;
47
+
42
48
const req0 = await reqPromise0 ;
43
- const startTimestamp = Date . now ( ) ;
44
49
45
50
const replayEvent0 = getReplayEvent ( req0 ) ;
46
51
expect ( replayEvent0 ) . toEqual ( getExpectedReplayEvent ( { } ) ) ;
@@ -54,6 +59,9 @@ for (let i = 0; i < 1; i++) {
54
59
const reqPromise2 = waitForReplayRequest ( page , 0 ) ;
55
60
56
61
// Wait for an incremental snapshot
62
+ // Wait half of the session max age (after initial flush), but account for potentially slow runners
63
+ const timePassed1 = Date . now ( ) - startTimestamp ;
64
+ await new Promise ( resolve => setTimeout ( resolve , Math . max ( SESSION_MAX_AGE / 2 - timePassed1 , 0 ) ) ) ;
57
65
await page . click ( '#button1' ) ;
58
66
59
67
const req1 = await reqPromise1 ;
@@ -86,11 +94,12 @@ for (let i = 0; i < 1; i++) {
86
94
] ) ,
87
95
) ;
88
96
89
- const replay = await getReplaySnapshot ( page ) ;
90
- const oldSessionId = replay . session ?. id ;
97
+ const replay1 = await getReplaySnapshot ( page ) ;
98
+ const oldSessionId = replay1 . session ?. id ;
91
99
92
100
// Wait for session to expire
93
- await new Promise ( resolve => setTimeout ( resolve , SESSION_MAX_AGE - ( Date . now ( ) - startTimestamp ) ) ) ;
101
+ const timePassed2 = Date . now ( ) - startTimestamp ;
102
+ await new Promise ( resolve => setTimeout ( resolve , Math . max ( SESSION_MAX_AGE - timePassed2 , 0 ) ) ) ;
94
103
await page . click ( '#button2' ) ;
95
104
96
105
const req2 = await reqPromise2 ;
0 commit comments