Skip to content

Conversation

@nicohrubec
Copy link
Member

@nicohrubec nicohrubec commented Jan 2, 2026

The drain() tests in promisebuffer.test.ts were flaky. The tests currently rely on real timers with small increments to test the timeout parameter of drain(). 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

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

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.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 9,348 - 8,829 +6%
GET With Sentry 1,743 19% 1,766 -1%
GET With Sentry (error only) 6,176 66% 6,083 +2%
POST Baseline 1,198 - 1,183 +1%
POST With Sentry 589 49% 581 +1%
POST With Sentry (error only) 1,065 89% 1,046 +2%
MYSQL Baseline 3,312 - 3,327 -0%
MYSQL With Sentry 492 15% 491 +0%
MYSQL With Sentry (error only) 2,702 82% 2,708 -0%

View base workflow run

@nicohrubec nicohrubec marked this pull request as ready for review January 2, 2026 08:45
Copy link
Member

@Lms24 Lms24 left a 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!

Comment on lines 108 to 110
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 {
Copy link
Member

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?

Copy link
Member Author

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

@nicohrubec nicohrubec merged commit 9fdd03f into develop Jan 2, 2026
401 of 403 checks passed
@nicohrubec nicohrubec deleted the nh/fix-flaky-promisebuffer branch January 2, 2026 09:11
@nicohrubec nicohrubec self-assigned this Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flaky CI]: Promisebuffer unit test in Core

3 participants