-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(replay): Ensure we do not try to flush when we force stop replay (#…
…8783) In our `stop()` method, we always tried to force a final flush when in `session` mode. However, that may lead to weird behaviour when we internally `stop()` due to a failure - e.g. think a send replay request fails, we do not want to force a flush again in that case. Note that in tests this seems to be generally passing because `flush()` usually has a running `_flushLock` at this time and thus does not attempt to flush again immediately but only schedules a flush later. I added a test that properly failed for this before and is now fixed.
- Loading branch information
Showing
8 changed files
with
110 additions
and
12 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
packages/browser-integration-tests/suites/replay/eventBufferError/template.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<button onclick="console.log('Test log')" id="button1">Click me</button> | ||
<button onclick="console.log('Test log 2')" id="button2">Click me</button> | ||
</body> | ||
</html> |
89 changes: 89 additions & 0 deletions
89
packages/browser-integration-tests/suites/replay/eventBufferError/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { envelopeRequestParser } from '../../../utils/helpers'; | ||
import { | ||
getDecompressedRecordingEvents, | ||
getReplaySnapshot, | ||
isReplayEvent, | ||
REPLAY_DEFAULT_FLUSH_MAX_DELAY, | ||
shouldSkipReplayTest, | ||
waitForReplayRequest, | ||
} from '../../../utils/replayHelpers'; | ||
|
||
sentryTest( | ||
'should stop recording when running into eventBuffer error', | ||
async ({ getLocalTestPath, page, forceFlushReplay }) => { | ||
if (shouldSkipReplayTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
await waitForReplayRequest(page); | ||
const replay = await getReplaySnapshot(page); | ||
expect(replay._isEnabled).toBe(true); | ||
|
||
await forceFlushReplay(); | ||
|
||
let called = 0; | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
const event = envelopeRequestParser(route.request()); | ||
|
||
// We only want to count replays here | ||
if (event && isReplayEvent(event)) { | ||
const events = getDecompressedRecordingEvents(route.request()); | ||
// this makes sure we ignore e.g. mouse move events which can otherwise lead to flakes | ||
if (events.length > 0) { | ||
called++; | ||
} | ||
} | ||
|
||
return route.fulfill({ | ||
status: 200, | ||
}); | ||
}); | ||
|
||
called = 0; | ||
|
||
/** | ||
* We test the following here: | ||
* 1. First click should add an event (so the eventbuffer is not empty) | ||
* 2. Second click should throw an error in eventBuffer (which should lead to stopping the replay) | ||
* 3. Nothing should be sent to API, as we stop the replay due to the eventBuffer error. | ||
*/ | ||
await page.evaluate(` | ||
window._count = 0; | ||
window._addEvent = window.Replay._replay.eventBuffer.addEvent.bind(window.Replay._replay.eventBuffer); | ||
window.Replay._replay.eventBuffer.addEvent = (...args) => { | ||
window._count++; | ||
if (window._count === 2) { | ||
throw new Error('provoked error'); | ||
} | ||
window._addEvent(...args); | ||
}; | ||
`); | ||
|
||
void page.click('#button1'); | ||
void page.click('#button2'); | ||
|
||
// Should immediately skip retrying and just cancel, no backoff | ||
// This waitForTimeout call should be okay, as we're not checking for any | ||
// further network requests afterwards. | ||
await page.waitForTimeout(REPLAY_DEFAULT_FLUSH_MAX_DELAY + 100); | ||
|
||
expect(called).toBe(0); | ||
|
||
const replay2 = await getReplaySnapshot(page); | ||
|
||
expect(replay2._isEnabled).toBe(false); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters