-
Notifications
You must be signed in to change notification settings - Fork 168
✅ fix flaky test #4168
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
✅ fix flaky test #4168
Conversation
`viewportObservable.spec.ts` changes the page to add scrollbars, causing some asynchronous events to be fired *after* the test has completed. If `recorder.spec.ts` is executed just after, its test might fail because it'll record those asynchronous events. This is the same issue we had with `scroll.spec.ts`. In the past, we tried to be smart and predict which events will be triggered, and wait for them. But it's a bit complex and not reliable on every browsers. This commit simplifies this workaround by waiting for two frames. When scrolling/changing viewport, the browser will first paint it, and then emit events. The second frame should reliably come after events are emitted (tested in Chrome, Firefox and Safari). Reproduce flaky test: git checkout 56a15f1 yarn test:unit --seed 26598
01da4b6 to
14258e6
Compare
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage 🔗 Commit SHA: 14258e6 | Docs | Datadog PR Page | Was this helpful? Give us feedback! |
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
| @@ -1,9 +1,13 @@ | |||
| const cleanupTasks: Array<() => void> = [] | |||
| type CleanupTask = () => unknown | |||
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.
🥜 nitpick:
| type CleanupTask = () => unknown | |
| type CleanupTask = () => void | Promise<void> |
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.
That was my initial thought, but then it lead to a typechecking issue https://gitlab.ddbuild.io/DataDog/browser-sdk/-/jobs/1420187767
Sooo... I just used unknown because we don't really care of the result?
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.
yeah, it's fine
Motivation
viewportObservable.spec.tschanges the page to add scrollbars, causing some asynchronous events to be fired after the test has completed. Ifrecorder.spec.tsis executed just after, its test might fail because it'll record those asynchronous events.This is the same issue we had with
scroll.spec.ts. In the past, we tried to be smart and predict which events will be triggered, and wait for them. But it's a bit complex and not reliable on every browsers.Changes
This commit simplifies this workaround by waiting for two frames. When scrolling/changing viewport, the browser will first paint it, and then emit events. The second frame should reliably come after events are emitted (tested in Chrome, Firefox and Safari).
Test instructions
Reproduce flaky test:
Confirm that it's gone when running the tests with the same seed after applying this PR changes
Checklist