Skip to content

test(replay): Fix flaky xhr/fetch request tests #7270

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 2 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/integration-tests/suites/replay/requests/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ window.Sentry = Sentry;
window.Replay = new Sentry.Replay({
flushMinDelay: 500,
flushMaxDelay: 500,
useCompression: true,
useCompression: false,
});

Sentry.init({
Expand Down
30 changes: 21 additions & 9 deletions packages/integration-tests/suites/replay/requests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { sentryTest } from '../../../utils/fixtures';
import { expectedFetchPerformanceSpan, expectedXHRPerformanceSpan } from '../../../utils/replayEventTemplates';
import { getReplayRecordingContent, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers';

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

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

await page.goto(url);
await page.click('#fetch');
await page.click('#go-background');

const { performanceSpans: spans0 } = getReplayRecordingContent(await reqPromise0);

const receivedResponse = page.waitForResponse('https://example.com');
await page.click('#fetch');
await receivedResponse;

const { performanceSpans: spans1 } = getReplayRecordingContent(await reqPromise1);
const performanceSpans = [...spans0, ...spans1];

const performanceSpans = [...spans0, ...spans1];
expect(performanceSpans).toContainEqual(expectedFetchPerformanceSpan);
});

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

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

await page.goto(url);
await page.click('#xhr');
await page.click('#go-background');

const { performanceSpans: spans0 } = getReplayRecordingContent(await reqPromise0);

const receivedResponse = page.waitForResponse('https://example.com');
await page.click('#xhr');
await receivedResponse;

const { performanceSpans: spans1 } = getReplayRecordingContent(await reqPromise1);

const performanceSpans = [...spans0, ...spans1];

expect(performanceSpans).toContainEqual(expectedXHRPerformanceSpan);
Expand Down