-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(ci): Reduce flakiness of Replay integration tests #6823
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
203bed6
fix(ci): Reduce flakiness of Replay integration tests
Lms24 77eeba6
wait for more requests
Lms24 16d15b5
wait -> action -> await request
Lms24 c2f26c4
wait for replay requests
Lms24 647d1b2
adjust search string
Lms24 2a218cc
ref waitForReplayRequest
Lms24 61b30f0
fix captureReplay tests
Lms24 8a2f4bc
refactor replay helpers
Lms24 e2e9449
remove unnecessary waitForTimeout call
Lms24 5cd3b0e
use constant for flush max delay
Lms24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,58 @@ | ||
import type { ReplayContainer } from '@sentry/replay/build/npm/types/types'; | ||
import type { Event, ReplayEvent } from '@sentry/types'; | ||
import type { Page, Request } from 'playwright'; | ||
|
||
import { envelopeRequestParser } from './helpers'; | ||
|
||
/** | ||
* Waits for a replay request to be sent by the page and returns it. | ||
* | ||
* Optionally, you can specify a segmentId to wait for a specific replay request, containing | ||
* the segment_id in the replay envelope. | ||
* This is useful for tests where you want to wait on multiple replay requests or check | ||
* segment order. | ||
* | ||
* @param page the playwright page object | ||
* @param segmentId the segment_id of the replay event | ||
* @returns | ||
*/ | ||
export function waitForReplayRequest(page: Page, segmentId?: number): Promise<Request> { | ||
return page.waitForRequest(req => { | ||
const postData = req.postData(); | ||
if (!postData) { | ||
return false; | ||
} | ||
|
||
try { | ||
const event = envelopeRequestParser(req); | ||
|
||
if (!isReplayEvent(event)) { | ||
return false; | ||
} | ||
|
||
if (segmentId !== undefined) { | ||
return event.segment_id === segmentId; | ||
} | ||
|
||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}); | ||
} | ||
|
||
function isReplayEvent(event: Event): event is ReplayEvent { | ||
return event.type === 'replay_event'; | ||
} | ||
|
||
/** | ||
* This returns the replay container (assuming it exists). | ||
* Note that due to how this works with playwright, this is a POJO copy of replay. | ||
* This means that we cannot access any methods on it, and also not mutate it in any way. | ||
*/ | ||
export async function getReplaySnapshot(page: Page): Promise<ReplayContainer> { | ||
const replayIntegration = await page.evaluate<{ _replay: ReplayContainer }>('window.Replay'); | ||
return replayIntegration._replay; | ||
} | ||
|
||
export const REPLAY_DEFAULT_FLUSH_MAX_DELAY = 5_000; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The below is
DEFAULT_FLUSH_MAX_DELAY + 1
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea here is just to wait for a flush cycle to ensure that nothing is sent anymore after the 400 response. Can't really use the constant here as it is not exported from the replay package. But I can add another constant here