-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(core): Use fake timers in promisebuffer tests to ensure deterministic behavior #18659
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
Conversation
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
Lms24
left a comment
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.
Thanks for fixing this!
| vi.useFakeTimers(); | ||
|
|
||
| const p1 = vi.fn(() => new Promise(resolve => setTimeout(resolve, 1))); | ||
| const p2 = vi.fn(() => new Promise(resolve => setTimeout(resolve, 1))); | ||
| const p3 = vi.fn(() => new Promise(resolve => setTimeout(resolve, 1))); | ||
| const p4 = vi.fn(() => new Promise(resolve => setTimeout(resolve, 1))); | ||
| const p5 = vi.fn(() => new Promise(resolve => setTimeout(resolve, 1))); | ||
| try { |
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.
l: Instead of the try/finally blocks, wdyt about using afterEach to reset timers?
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.
Right, I agree. I did it like this because we only use fake timers in these two tests (there are still real timeouts in other tests), but should be fine to just always use it and it's a bit cleaner
The
drain()tests inpromisebuffer.test.tswere flaky. The tests currently rely on real timers with small increments to test the timeout parameter ofdrain(). This can lead to race conditions between promise resolution and drain timeout.This PR switches to Vitest's fake timers, giving us deterministic control over time progression and should thereby eliminate the race condition.
Closes #18642