Skip to content

Commit 67b0684

Browse files
authored
test(replay): Fix flaky xhr/fetch request tests (#7270)
A newly added replay test (#7044) for checking for the presence of XHR/fetch request spans was flaky on CI. This was caused by two reasons: 1. We didn't explicitly await for the fetch/xhr requests to finish before waiting for the replay event which we expected to contain the span. With this fix we now wait that the browser actually received the response. 2. The tests were only flaky on Firefox. After some research (this seems to be somewhat of a [known problem](microsoft/playwright#11390 (comment)) in some situations) I decided to simply skip for FF. I think this is reasonably pragmatic as we're still testing on Chromium and Webkit.
1 parent e471837 commit 67b0684

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

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

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

1010
Sentry.init({

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import { sentryTest } from '../../../utils/fixtures';
44
import { expectedFetchPerformanceSpan, expectedXHRPerformanceSpan } from '../../../utils/replayEventTemplates';
55
import { getReplayRecordingContent, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers';
66

7-
sentryTest('replay recording should contain fetch request span', async ({ getLocalTestPath, page }) => {
8-
if (shouldSkipReplayTest()) {
7+
sentryTest('replay recording should contain fetch request span', async ({ getLocalTestPath, page, browserName }) => {
8+
// For some reason, observing and waiting for requests in firefox is extremely flaky.
9+
// We therefore skip this test for firefox and only test on chromium/webkit.
10+
// Possibly related: https://github.com/microsoft/playwright/issues/11390
11+
if (shouldSkipReplayTest() || browserName === 'firefox') {
912
sentryTest.skip();
1013
}
1114

@@ -31,18 +34,23 @@ sentryTest('replay recording should contain fetch request span', async ({ getLoc
3134
const url = await getLocalTestPath({ testDir: __dirname });
3235

3336
await page.goto(url);
34-
await page.click('#fetch');
3537
await page.click('#go-background');
36-
3738
const { performanceSpans: spans0 } = getReplayRecordingContent(await reqPromise0);
39+
40+
const receivedResponse = page.waitForResponse('https://example.com');
41+
await page.click('#fetch');
42+
await receivedResponse;
43+
3844
const { performanceSpans: spans1 } = getReplayRecordingContent(await reqPromise1);
39-
const performanceSpans = [...spans0, ...spans1];
4045

46+
const performanceSpans = [...spans0, ...spans1];
4147
expect(performanceSpans).toContainEqual(expectedFetchPerformanceSpan);
4248
});
4349

44-
sentryTest('replay recording should contain XHR request span', async ({ getLocalTestPath, page }) => {
45-
if (shouldSkipReplayTest()) {
50+
sentryTest('replay recording should contain XHR request span', async ({ getLocalTestPath, page, browserName }) => {
51+
// For some reason, observing and waiting for requests in firefox is extremely flaky.
52+
// We therefore skip this test for firefox and only test on chromium/webkit.
53+
if (shouldSkipReplayTest() || browserName === 'firefox') {
4654
sentryTest.skip();
4755
}
4856

@@ -68,11 +76,15 @@ sentryTest('replay recording should contain XHR request span', async ({ getLocal
6876
const url = await getLocalTestPath({ testDir: __dirname });
6977

7078
await page.goto(url);
71-
await page.click('#xhr');
7279
await page.click('#go-background');
73-
7480
const { performanceSpans: spans0 } = getReplayRecordingContent(await reqPromise0);
81+
82+
const receivedResponse = page.waitForResponse('https://example.com');
83+
await page.click('#xhr');
84+
await receivedResponse;
85+
7586
const { performanceSpans: spans1 } = getReplayRecordingContent(await reqPromise1);
87+
7688
const performanceSpans = [...spans0, ...spans1];
7789

7890
expect(performanceSpans).toContainEqual(expectedXHRPerformanceSpan);

0 commit comments

Comments
 (0)