-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(replay): Clear event buffer when full and in buffer mode (#14078)
This makes a change so that when the event buffer is full, we will clear it and wait for the next checkout instead of erroring and stopping the replay buffering. This does mean that it's possible an exception occurs in-between the filled buffer and the next checkout, where we will have an empty replay
- Loading branch information
Showing
7 changed files
with
135 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
75 changes: 75 additions & 0 deletions
75
packages/replay-internal/test/integration/eventBuffer.test.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @vitest-environment jsdom | ||
*/ | ||
|
||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
||
import { WINDOW } from '../../src/constants'; | ||
import type { Replay } from '../../src/integration'; | ||
import type { ReplayContainer } from '../../src/replay'; | ||
import { addEvent } from '../../src/util/addEvent'; | ||
|
||
// mock functions need to be imported first | ||
import { BASE_TIMESTAMP, mockSdk } from '../index'; | ||
import { getTestEventCheckout, getTestEventIncremental } from '../utils/getTestEvent'; | ||
import { useFakeTimers } from '../utils/use-fake-timers'; | ||
|
||
useFakeTimers(); | ||
|
||
describe('Integration | eventBuffer | Event Buffer Max Size', () => { | ||
let replay: ReplayContainer; | ||
let integration: Replay; | ||
const prevLocation = WINDOW.location; | ||
|
||
beforeEach(async () => { | ||
vi.setSystemTime(new Date(BASE_TIMESTAMP)); | ||
|
||
({ replay, integration } = await mockSdk()); | ||
|
||
await vi.runAllTimersAsync(); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
afterEach(async () => { | ||
vi.setSystemTime(new Date(BASE_TIMESTAMP)); | ||
integration && (await integration.stop()); | ||
Object.defineProperty(WINDOW, 'location', { | ||
value: prevLocation, | ||
writable: true, | ||
}); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('does not add replay breadcrumb when stopped due to event buffer limit', async () => { | ||
const TEST_EVENT = getTestEventIncremental({ timestamp: BASE_TIMESTAMP }); | ||
|
||
vi.mock('../../src/constants', async requireActual => ({ | ||
...(await requireActual<any>()), | ||
REPLAY_MAX_EVENT_BUFFER_SIZE: 500, | ||
})); | ||
|
||
await integration.stop(); | ||
integration.startBuffering(); | ||
|
||
await addEvent(replay, TEST_EVENT); | ||
|
||
expect(replay.eventBuffer?.hasEvents).toBe(true); | ||
expect(replay.eventBuffer?.['hasCheckout']).toBe(true); | ||
|
||
// This should should go over max buffer size | ||
await addEvent(replay, TEST_EVENT); | ||
// buffer should be cleared and wait for next checkout | ||
expect(replay.eventBuffer?.hasEvents).toBe(false); | ||
expect(replay.eventBuffer?.['hasCheckout']).toBe(false); | ||
|
||
await addEvent(replay, TEST_EVENT); | ||
expect(replay.eventBuffer?.hasEvents).toBe(false); | ||
expect(replay.eventBuffer?.['hasCheckout']).toBe(false); | ||
|
||
await addEvent(replay, getTestEventCheckout({ timestamp: Date.now() }), true); | ||
expect(replay.eventBuffer?.hasEvents).toBe(true); | ||
expect(replay.eventBuffer?.['hasCheckout']).toBe(true); | ||
|
||
vi.resetAllMocks(); | ||
}); | ||
}); |
This file contains 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