Skip to content

Commit 937cc24

Browse files
committed
fix test?
1 parent dce20d7 commit 937cc24

File tree

2 files changed

+15
-6
lines changed
  • packages/integration-tests/suites/replay

2 files changed

+15
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
// Session should expire after 2s - keep in sync with init.js
1616
const SESSION_TIMEOUT = 2000;
1717

18-
for (let i = 0; i < 100; i++) {
18+
for (let i = 0; i < 1; i++) {
1919
sentryTest(`handles an expired session RUN ${i}`, async ({ getLocalTestPath, page }) => {
2020
if (shouldSkipReplayTest()) {
2121
sentryTest.skip();

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const SESSION_MAX_AGE = 4000;
1919
The main difference between this and sessionExpiry test, is that here we wait for the overall time (4s)
2020
in multiple steps (2s, 2s) instead of waiting for the whole time at once (4s).
2121
*/
22-
for (let i = 0; i < 1; i++) {
22+
for (let i = 0; i < 100; i++) {
2323
sentryTest(`handles session that exceeds max age RUN ${i}`, async ({ getLocalTestPath, page }) => {
2424
if (shouldSkipReplayTest()) {
2525
sentryTest.skip();
@@ -39,8 +39,13 @@ for (let i = 0; i < 1; i++) {
3939
const url = await getLocalTestPath({ testDir: __dirname });
4040

4141
await page.goto(url);
42+
43+
const replay0 = await getReplaySnapshot(page);
44+
// We use the `initialTimestamp` of the replay to do any time based calculations
45+
// @ts-ignore this is fine
46+
const startTimestamp = replay0._context.initialTimestamp;
47+
4248
const req0 = await reqPromise0;
43-
const startTimestamp = Date.now();
4449

4550
const replayEvent0 = getReplayEvent(req0);
4651
expect(replayEvent0).toEqual(getExpectedReplayEvent({}));
@@ -54,6 +59,9 @@ for (let i = 0; i < 1; i++) {
5459
const reqPromise2 = waitForReplayRequest(page, 0);
5560

5661
// Wait for an incremental snapshot
62+
// Wait half of the session max age (after initial flush), but account for potentially slow runners
63+
const timePassed1 = Date.now() - startTimestamp;
64+
await new Promise(resolve => setTimeout(resolve, Math.max(SESSION_MAX_AGE / 2 - timePassed1, 0)));
5765
await page.click('#button1');
5866

5967
const req1 = await reqPromise1;
@@ -86,11 +94,12 @@ for (let i = 0; i < 1; i++) {
8694
]),
8795
);
8896

89-
const replay = await getReplaySnapshot(page);
90-
const oldSessionId = replay.session?.id;
97+
const replay1 = await getReplaySnapshot(page);
98+
const oldSessionId = replay1.session?.id;
9199

92100
// Wait for session to expire
93-
await new Promise(resolve => setTimeout(resolve, SESSION_MAX_AGE - (Date.now() - startTimestamp)));
101+
const timePassed2 = Date.now() - startTimestamp;
102+
await new Promise(resolve => setTimeout(resolve, Math.max(SESSION_MAX_AGE - timePassed2, 0)));
94103
await page.click('#button2');
95104

96105
const req2 = await reqPromise2;

0 commit comments

Comments
 (0)