Skip to content

Commit

Permalink
fix flaky test?
Browse files Browse the repository at this point in the history
run 100 times


fix flaky?


unrun 100
  • Loading branch information
mydea committed Mar 8, 2023
1 parent e4da1f8 commit ea80817
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,26 @@ sentryTest(
sentryTest.skip();
}

// We want to ensure to check the correct event payloads
let firstInputMutationSegmentId: number | undefined = undefined;
const reqPromise0 = waitForReplayRequest(page, 0);
const reqPromise1 = waitForReplayRequest(page, 1);
const reqPromise2 = waitForReplayRequest(page, 2);
const reqPromise1 = waitForReplayRequest(page, (event, res) => {
const check =
firstInputMutationSegmentId === undefined && getIncrementalRecordingSnapshots(res).some(isInputMutation);

if (check) {
firstInputMutationSegmentId = event.segment_id;
}

return check;
});
const reqPromise2 = waitForReplayRequest(page, (event, res) => {
return (
typeof firstInputMutationSegmentId === 'number' &&
firstInputMutationSegmentId < event.segment_id &&
getIncrementalRecordingSnapshots(res).some(isInputMutation)
);
});

await page.route('https://dsn.ingest.sentry.io/**/*', route => {
return route.fulfill({
Expand All @@ -39,13 +56,13 @@ sentryTest(
const url = await getLocalTestPath({ testDir: __dirname });

await page.goto(url);

await reqPromise0;

const text = 'test';

await page.locator('#input').fill(text);
await forceFlushReplay();

const snapshots = getIncrementalRecordingSnapshots(await reqPromise1).filter(isInputMutation);
const lastSnapshot = snapshots[snapshots.length - 1];
expect(lastSnapshot.data.text).toBe('*'.repeat(text.length));
Expand All @@ -66,9 +83,26 @@ sentryTest(
sentryTest.skip();
}

// We want to ensure to check the correct event payloads
let firstInputMutationSegmentId: number | undefined = undefined;
const reqPromise0 = waitForReplayRequest(page, 0);
const reqPromise1 = waitForReplayRequest(page, 1);
const reqPromise2 = waitForReplayRequest(page, 2);
const reqPromise1 = waitForReplayRequest(page, (event, res) => {
const check =
firstInputMutationSegmentId === undefined && getIncrementalRecordingSnapshots(res).some(isInputMutation);

if (check) {
firstInputMutationSegmentId = event.segment_id;
}

return check;
});
const reqPromise2 = waitForReplayRequest(page, (event, res) => {
return (
typeof firstInputMutationSegmentId === 'number' &&
firstInputMutationSegmentId < event.segment_id &&
getIncrementalRecordingSnapshots(res).some(isInputMutation)
);
});

await page.route('https://dsn.ingest.sentry.io/**/*', route => {
return route.fulfill({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
// Session should expire after 2s - keep in sync with init.js
const SESSION_TIMEOUT = 2000;

sentryTest('handles an expired session RUN', async ({ getLocalTestPath, page }) => {
sentryTest('handles an expired session', async ({ getLocalTestPath, page }) => {
if (shouldSkipReplayTest()) {
sentryTest.skip();
}
Expand Down
12 changes: 11 additions & 1 deletion packages/integration-tests/utils/replayHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ export type RecordingSnapshot = FullRecordingSnapshot | IncrementalRecordingSnap
* @param segmentId the segment_id of the replay event
* @returns
*/
export function waitForReplayRequest(page: Page, segmentId?: number): Promise<Response> {
export function waitForReplayRequest(
page: Page,
segmentIdOrCallback?: number | ((event: ReplayEvent, res: Response) => boolean),
): Promise<Response> {
const segmentId = typeof segmentIdOrCallback === 'number' ? segmentIdOrCallback : undefined;
const callback = typeof segmentIdOrCallback === 'function' ? segmentIdOrCallback : undefined;

return page.waitForResponse(res => {
const req = res.request();

Expand All @@ -62,6 +68,10 @@ export function waitForReplayRequest(page: Page, segmentId?: number): Promise<Re
return false;
}

if (callback) {
return callback(event, res);
}

if (segmentId !== undefined) {
return event.segment_id === segmentId;
}
Expand Down

0 comments on commit ea80817

Please sign in to comment.