@@ -442,4 +442,46 @@ describe('Integration | flush', () => {
442
442
443
443
replay . getOptions ( ) . _experiments . traceInternals = false ;
444
444
} ) ;
445
+
446
+ /**
447
+ * This tests the case where a flush happens in time,
448
+ * but something takes too long (e.g. because we are idle, ...)
449
+ * so by the time we actually send the replay it's too late.
450
+ * In this case, we want to stop the replay.
451
+ */
452
+ it ( 'stops if flushing after maxSessionLife' , async ( ) => {
453
+ replay . timeouts . maxSessionLife = 100_000 ;
454
+
455
+ sessionStorage . clear ( ) ;
456
+ clearSession ( replay ) ;
457
+ replay [ '_loadAndCheckSession' ] ( ) ;
458
+ await new Promise ( process . nextTick ) ;
459
+ jest . setSystemTime ( BASE_TIMESTAMP ) ;
460
+
461
+ replay . eventBuffer ! . clear ( ) ;
462
+
463
+ // We do not care about this warning here
464
+ replay . eventBuffer ! . hasCheckout = true ;
465
+
466
+ // We want to simulate that flushing happens _way_ late
467
+ replay [ '_addPerformanceEntries' ] = ( ) => {
468
+ return new Promise ( resolve => setTimeout ( resolve , 140_000 ) ) ;
469
+ } ;
470
+
471
+ // Add event inside of session life timespan
472
+ const TEST_EVENT = { data : { } , timestamp : BASE_TIMESTAMP + 100 , type : 2 } ;
473
+ mockRecord . _emitter ( TEST_EVENT ) ;
474
+
475
+ await advanceTimers ( DEFAULT_FLUSH_MIN_DELAY ) ;
476
+ await advanceTimers ( 160_000 ) ;
477
+
478
+ expect ( mockFlush ) . toHaveBeenCalledTimes ( 2 ) ;
479
+ expect ( mockSendReplay ) . toHaveBeenCalledTimes ( 0 ) ;
480
+ expect ( replay . isEnabled ( ) ) . toBe ( false ) ;
481
+
482
+ replay . timeouts . maxSessionLife = MAX_SESSION_LIFE ;
483
+
484
+ // Start again for following tests
485
+ await replay . start ( ) ;
486
+ } ) ;
445
487
} ) ;
0 commit comments