-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref(replay): Avoid duplicate debounce timers #6863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,8 @@ describe('Integration | sendReplayEvent', () => { | |
|
||
({ replay } = await mockSdk({ | ||
replayOptions: { | ||
flushMinDelay: 5_000, | ||
flushMaxDelay: 15_000, | ||
stickySession: false, | ||
_experiments: { | ||
captureExceptions: true, | ||
|
@@ -146,13 +148,13 @@ describe('Integration | sendReplayEvent', () => { | |
expect(replay.eventBuffer?.pendingLength).toBe(0); | ||
}); | ||
|
||
it('uploads a replay event if 15 seconds have elapsed since the last replay upload', async () => { | ||
it('uploads a replay event if maxFlushDelay is set 15 seconds have elapsed since the last replay upload', async () => { | ||
const TEST_EVENT = { data: {}, timestamp: BASE_TIMESTAMP, type: 3 }; | ||
// Fire a new event every 4 seconds, 4 times | ||
[...Array(4)].forEach(() => { | ||
for (let i = 0; i < 4; i++) { | ||
mockRecord._emitter(TEST_EVENT); | ||
jest.advanceTimersByTime(4000); | ||
}); | ||
jest.advanceTimersByTime(4_000); | ||
} | ||
|
||
// We are at time = +16seconds now (relative to BASE_TIMESTAMP) | ||
// The next event should cause an upload immediately | ||
|
@@ -247,60 +249,6 @@ describe('Integration | sendReplayEvent', () => { | |
expect(replay.eventBuffer?.pendingLength).toBe(0); | ||
}); | ||
|
||
it('uploads a replay event if 5 seconds have elapsed since the last replay event occurred', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test was actually here twice! |
||
const TEST_EVENT = { data: {}, timestamp: BASE_TIMESTAMP, type: 3 }; | ||
mockRecord._emitter(TEST_EVENT); | ||
// Pretend 5 seconds have passed | ||
const ELAPSED = 5000; | ||
await advanceTimers(ELAPSED); | ||
|
||
expect(mockRecord.takeFullSnapshot).not.toHaveBeenCalled(); | ||
expect(mockTransportSend).toHaveBeenCalledTimes(1); | ||
expect(replay).toHaveLastSentReplay({ recordingData: JSON.stringify([TEST_EVENT]) }); | ||
|
||
// No user activity to trigger an update | ||
expect(replay.session?.lastActivity).toBe(BASE_TIMESTAMP); | ||
expect(replay.session?.segmentId).toBe(1); | ||
|
||
// events array should be empty | ||
expect(replay.eventBuffer?.pendingLength).toBe(0); | ||
}); | ||
|
||
it('uploads a replay event if 15 seconds have elapsed since the last replay upload', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for this test, exact duplicate 😅 |
||
const TEST_EVENT = { data: {}, timestamp: BASE_TIMESTAMP, type: 3 }; | ||
// Fire a new event every 4 seconds, 4 times | ||
[...Array(4)].forEach(() => { | ||
mockRecord._emitter(TEST_EVENT); | ||
jest.advanceTimersByTime(4000); | ||
}); | ||
|
||
// We are at time = +16seconds now (relative to BASE_TIMESTAMP) | ||
// The next event should cause an upload immediately | ||
mockRecord._emitter(TEST_EVENT); | ||
await new Promise(process.nextTick); | ||
|
||
expect(replay).toHaveLastSentReplay({ | ||
recordingData: JSON.stringify([...Array(5)].map(() => TEST_EVENT)), | ||
}); | ||
|
||
// There should also not be another attempt at an upload 5 seconds after the last replay event | ||
mockTransportSend.mockClear(); | ||
await advanceTimers(DEFAULT_FLUSH_MIN_DELAY); | ||
|
||
expect(replay).not.toHaveLastSentReplay(); | ||
|
||
expect(replay.session?.lastActivity).toBe(BASE_TIMESTAMP); | ||
expect(replay.session?.segmentId).toBe(1); | ||
// events array should be empty | ||
expect(replay.eventBuffer?.pendingLength).toBe(0); | ||
|
||
// Let's make sure it continues to work | ||
mockTransportSend.mockClear(); | ||
mockRecord._emitter(TEST_EVENT); | ||
await advanceTimers(DEFAULT_FLUSH_MIN_DELAY); | ||
expect(replay).toHaveLastSentReplay({ recordingData: JSON.stringify([TEST_EVENT]) }); | ||
}); | ||
|
||
it('uploads a dom breadcrumb 5 seconds after listener receives an event', async () => { | ||
domHandler({ | ||
name: 'click', | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, any clue why this test wasn't failing before? 😅 I suspect there is actually a bug (??) that is fixed here, but not sure - we do have a test for the wait time being equal, but maybe it doesn't catch some aspect...?!