Skip to content

Commit 0c16c1e

Browse files
committed
test(replay): Potentially fix flaky flush test
1 parent 80cb7a5 commit 0c16c1e

File tree

2 files changed

+59
-51
lines changed

2 files changed

+59
-51
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
</head>
66
<body>
77
<button id="go-background">New Tab</button>
8+
<button id="something">Do something</button>
89
</body>
910
</html>

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

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,63 @@ import { getReplayEvent, shouldSkipReplayTest, waitForReplayRequest } from '../.
77
// Sync this with init.js - not we take seconds here instead of ms
88
const FLUSH_DELAY_SECONDS = 0.5;
99

10-
sentryTest('replay recording flushes every 5s', async ({ getLocalTestPath, page }) => {
11-
if (shouldSkipReplayTest()) {
12-
sentryTest.skip();
13-
}
14-
15-
const reqPromise0 = waitForReplayRequest(page, 0);
16-
const reqPromise1 = waitForReplayRequest(page, 1);
17-
const reqPromise2 = waitForReplayRequest(page, 2);
18-
19-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
20-
return route.fulfill({
21-
status: 200,
22-
contentType: 'application/json',
23-
body: JSON.stringify({ id: 'test-id' }),
10+
for (let index = 0; index < 25; index++) {
11+
console.log('test', index);
12+
sentryTest(`replay recording flushes every FLUSH_DELAY_SECONDS (${index})}`, async ({ getLocalTestPath, page }) => {
13+
if (shouldSkipReplayTest()) {
14+
sentryTest.skip();
15+
}
16+
17+
const reqPromise0 = waitForReplayRequest(page, 0);
18+
const reqPromise1 = waitForReplayRequest(page, 1);
19+
const reqPromise2 = waitForReplayRequest(page, 2);
20+
21+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
22+
return route.fulfill({
23+
status: 200,
24+
contentType: 'application/json',
25+
body: JSON.stringify({ id: 'test-id' }),
26+
});
2427
});
25-
});
2628

27-
const url = await getLocalTestPath({ testDir: __dirname });
28-
29-
await page.goto(url);
30-
const replayEvent0 = getReplayEvent(await reqPromise0);
31-
expect(replayEvent0).toEqual(getExpectedReplayEvent());
32-
33-
// trigger mouse click
34-
void page.click('#go-background');
35-
36-
const replayEvent1 = getReplayEvent(await reqPromise1);
37-
expect(replayEvent1).toEqual(getExpectedReplayEvent({ replay_start_timestamp: undefined, segment_id: 1, urls: [] }));
38-
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++) {
41-
setTimeout(async () => {
42-
try {
43-
await page.click('#go-background');
44-
} catch {
45-
// ignore errors here, we don't care if the page is closed
46-
}
47-
}, i * 100);
48-
}
49-
50-
const replayEvent2 = getReplayEvent(await reqPromise2);
51-
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);
62-
});
29+
const url = await getLocalTestPath({ testDir: __dirname });
30+
31+
await page.goto(url);
32+
const replayEvent0 = getReplayEvent(await reqPromise0);
33+
expect(replayEvent0).toEqual(getExpectedReplayEvent());
34+
35+
// trigger mouse click
36+
void page.click('#go-background');
37+
38+
const replayEvent1 = getReplayEvent(await reqPromise1);
39+
expect(replayEvent1).toEqual(
40+
getExpectedReplayEvent({ replay_start_timestamp: undefined, segment_id: 1, urls: [] }),
41+
);
42+
43+
// trigger mouse click every 100ms, it should still flush after 0.5s even if clicks are ongoing
44+
for (let i = 0; i < 70; i++) {
45+
setTimeout(async () => {
46+
try {
47+
await page.click('#something');
48+
} catch {
49+
// ignore errors here, we don't care if the page is closed
50+
}
51+
}, i * 100);
52+
}
53+
54+
const replayEvent2 = getReplayEvent(await reqPromise2);
55+
expect(replayEvent2).toEqual(
56+
getExpectedReplayEvent({ replay_start_timestamp: undefined, segment_id: 2, urls: [] }),
57+
);
58+
59+
// Ensure time diff is about 500ms between each event
60+
const diff1 = replayEvent1.timestamp! - replayEvent0.timestamp!;
61+
const diff2 = replayEvent2.timestamp! - replayEvent1.timestamp!;
62+
63+
// We want to check that the diff is between 0.1 and 0.9 seconds, to accomodate for some wiggle room
64+
expect(diff1).toBeLessThan(FLUSH_DELAY_SECONDS + 0.4);
65+
expect(diff1).toBeGreaterThanOrEqual(FLUSH_DELAY_SECONDS - 0.4);
66+
expect(diff2).toBeLessThan(FLUSH_DELAY_SECONDS + 0.4);
67+
expect(diff2).toBeGreaterThanOrEqual(FLUSH_DELAY_SECONDS - 0.4);
68+
});
69+
}

0 commit comments

Comments
 (0)