Skip to content

Commit 4ae08fe

Browse files
authored
test(replay): Fix flaky flush test (#7268)
Fix the flakiness of our replay event flushing test by slightly changing the test requirements/expectations: * Disabled compression to avoid potential timing problems * Instead of asserting that a flush happens within a certain time frame from the last flush, we ease up this expectation so that we only expect _that_ another flush happens after the previous one, given that click events happened in between. * Instead of forcing a flush by triggering a visibility change (like we do a lot in other tests to avoid flakes), this test focuses on the max delay of flushing, thereby ensuring that our flushes are not debounced to eternity.
1 parent 67b0684 commit 4ae08fe

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

packages/integration-tests/suites/replay/flushing/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ window.Sentry = Sentry;
44
window.Replay = new Sentry.Replay({
55
flushMinDelay: 500,
66
flushMaxDelay: 500,
7+
useCompression: false,
78
});
89

910
Sentry.init({

packages/integration-tests/suites/replay/flushing/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<meta charset="utf-8" />
55
</head>
66
<body>
7-
<button id="go-background">New Tab</button>
7+
<button id="something">Do something</button>
88
</body>
99
</html>

packages/integration-tests/suites/replay/flushing/test.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ import { sentryTest } from '../../../utils/fixtures';
44
import { getExpectedReplayEvent } from '../../../utils/replayEventTemplates';
55
import { getReplayEvent, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers';
66

7-
// Sync this with init.js - not we take seconds here instead of ms
8-
const FLUSH_DELAY_SECONDS = 0.5;
9-
10-
sentryTest('replay recording flushes every 5s', async ({ getLocalTestPath, page }) => {
7+
/*
8+
* In this test we're explicitly not forcing a flush by triggering a visibility change.
9+
* Instead, we want to verify that the `flushMaxDelay` works in the sense that eventually
10+
* a flush is triggered if some events are in the buffer.
11+
* Note: Due to timing problems and inconsistencies in Playwright/CI, we can't reliably
12+
* assert on the flush timestamps. Therefore we only assert that events were eventually
13+
* sent (i.e. flushed).
14+
*/
15+
sentryTest('replay events are flushed after max flush delay was reached', async ({ getLocalTestPath, page }) => {
1116
if (shouldSkipReplayTest()) {
1217
sentryTest.skip();
1318
}
@@ -30,17 +35,18 @@ sentryTest('replay recording flushes every 5s', async ({ getLocalTestPath, page
3035
const replayEvent0 = getReplayEvent(await reqPromise0);
3136
expect(replayEvent0).toEqual(getExpectedReplayEvent());
3237

33-
// trigger mouse click
34-
void page.click('#go-background');
38+
// trigger one mouse click
39+
void page.click('#something');
3540

41+
// this must eventually lead to a flush after the max delay was reached
3642
const replayEvent1 = getReplayEvent(await reqPromise1);
3743
expect(replayEvent1).toEqual(getExpectedReplayEvent({ replay_start_timestamp: undefined, segment_id: 1, urls: [] }));
3844

39-
// trigger mouse click every 100ms, it should still flush after 5s even if clicks are ongoing
40-
for (let i = 0; i < 70; i++) {
45+
// trigger mouse click every 100ms, it should still flush after the max delay even if clicks are ongoing
46+
for (let i = 0; i < 700; i++) {
4147
setTimeout(async () => {
4248
try {
43-
await page.click('#go-background');
49+
await page.click('#something');
4450
} catch {
4551
// ignore errors here, we don't care if the page is closed
4652
}
@@ -49,14 +55,4 @@ sentryTest('replay recording flushes every 5s', async ({ getLocalTestPath, page
4955

5056
const replayEvent2 = getReplayEvent(await reqPromise2);
5157
expect(replayEvent2).toEqual(getExpectedReplayEvent({ replay_start_timestamp: undefined, segment_id: 2, urls: [] }));
52-
53-
// Ensure time diff is about 500ms between each event
54-
const diff1 = replayEvent1.timestamp! - replayEvent0.timestamp!;
55-
const diff2 = replayEvent2.timestamp! - replayEvent1.timestamp!;
56-
57-
// We want to check that the diff is between 0.1 and 0.9 seconds, to accomodate for some wiggle room
58-
expect(diff1).toBeLessThan(FLUSH_DELAY_SECONDS + 0.4);
59-
expect(diff1).toBeGreaterThanOrEqual(FLUSH_DELAY_SECONDS - 0.4);
60-
expect(diff2).toBeLessThan(FLUSH_DELAY_SECONDS + 0.4);
61-
expect(diff2).toBeGreaterThanOrEqual(FLUSH_DELAY_SECONDS - 0.4);
6258
});

0 commit comments

Comments
 (0)