@@ -226,6 +226,71 @@ describe('Integration | errorSampleRate', () => {
226
226
} ) ;
227
227
} ) ;
228
228
229
+ it ( 'handles multiple simultaneous flushes' , async ( ) => {
230
+ const TEST_EVENT = { data : { } , timestamp : BASE_TIMESTAMP , type : 3 } ;
231
+ mockRecord . _emitter ( TEST_EVENT ) ;
232
+ const optionsEvent = createOptionsEvent ( replay ) ;
233
+
234
+ expect ( mockRecord . takeFullSnapshot ) . not . toHaveBeenCalled ( ) ;
235
+ expect ( replay ) . not . toHaveLastSentReplay ( ) ;
236
+
237
+ // Does not capture on mouse click
238
+ domHandler ( {
239
+ name : 'click' ,
240
+ } ) ;
241
+ jest . runAllTimers ( ) ;
242
+ await new Promise ( process . nextTick ) ;
243
+ expect ( replay ) . not . toHaveLastSentReplay ( ) ;
244
+
245
+ replay . sendBufferedReplayOrFlush ( { continueRecording : true } ) ;
246
+ replay . sendBufferedReplayOrFlush ( { continueRecording : true } ) ;
247
+
248
+ await waitForBufferFlush ( ) ;
249
+
250
+ expect ( replay ) . toHaveSentReplay ( {
251
+ recordingPayloadHeader : { segment_id : 0 } ,
252
+ replayEventPayload : expect . objectContaining ( {
253
+ replay_type : 'buffer' ,
254
+ } ) ,
255
+ recordingData : JSON . stringify ( [
256
+ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } ,
257
+ optionsEvent ,
258
+ TEST_EVENT ,
259
+ {
260
+ type : 5 ,
261
+ timestamp : BASE_TIMESTAMP ,
262
+ data : {
263
+ tag : 'breadcrumb' ,
264
+ payload : {
265
+ timestamp : BASE_TIMESTAMP / 1000 ,
266
+ type : 'default' ,
267
+ category : 'ui.click' ,
268
+ message : '<unknown>' ,
269
+ data : { } ,
270
+ } ,
271
+ } ,
272
+ } ,
273
+ ] ) ,
274
+ } ) ;
275
+
276
+ jest . advanceTimersByTime ( DEFAULT_FLUSH_MIN_DELAY ) ;
277
+ // Check that click will not get captured
278
+ domHandler ( {
279
+ name : 'click' ,
280
+ } ) ;
281
+
282
+ await waitForFlush ( ) ;
283
+
284
+ // This is still the last replay sent since we passed `continueRecording:
285
+ // false`.
286
+ expect ( replay ) . toHaveLastSentReplay ( {
287
+ recordingPayloadHeader : { segment_id : 1 } ,
288
+ replayEventPayload : expect . objectContaining ( {
289
+ replay_type : 'buffer' ,
290
+ } ) ,
291
+ } ) ;
292
+ } ) ;
293
+
229
294
// This tests a regression where we were calling flush indiscriminantly in `stop()`
230
295
it ( 'does not upload a replay event if error is not sampled' , async ( ) => {
231
296
// We are trying to replicate the case where error rate is 0 and session
@@ -620,7 +685,8 @@ describe('Integration | errorSampleRate', () => {
620
685
621
686
await waitForBufferFlush ( ) ;
622
687
623
- expect ( replay . session ?. started ) . toBe ( BASE_TIMESTAMP + ELAPSED + TICK + TICK ) ;
688
+ // This is still the timestamp from the full snapshot we took earlier
689
+ expect ( replay . session ?. started ) . toBe ( BASE_TIMESTAMP + ELAPSED + TICK ) ;
624
690
625
691
// Does not capture mouse click
626
692
expect ( replay ) . toHaveSentReplay ( {
0 commit comments