Skip to content

fix(runner): fast sequential task updates missing #8121

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

Conversation

AriPerkkio
Copy link
Member

@AriPerkkio AriPerkkio commented Jun 8, 2025

Description

The sendTasksUpdateThrottled is called sequentially with suite-prepare and test-prepare. The suite-prepare is reported to main thread immediately. The test-prepare hits throttle's limiter, and is ignored. It is reported to main thread on the next invokation of sendTasksUpdateThrottled, which is test-finished. If user's test case is taking 5000ms, the reporting of test-prepare takes 5000ms too.

As solution we'll need to make sure throttle flushes its queue even when it's not called again.

Note:

  • As onUserConsoleLog is not throttled, it's still possible that reporters see test case's console logs before onTestCaseReady, if logs happen 100ms within the start.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@AriPerkkio AriPerkkio force-pushed the fix/runner-task-update-timing branch 3 times, most recently from a09e008 to 2493350 Compare June 8, 2025 14:19
@AriPerkkio AriPerkkio force-pushed the fix/runner-task-update-timing branch from 2493350 to cecaa86 Compare June 8, 2025 15:24
@AriPerkkio AriPerkkio marked this pull request as ready for review June 8, 2025 15:44
Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! throttle implementation by me (and copilot) was too poor 😅 #7700

I just checked tanstack's throttle implementation https://github.com/TanStack/pacer/blob/0f2cd3cfc45956dc40e6b865210c47d56f5fc129/packages/pacer/src/throttler.ts#L155 and it looks like the concept is called trailing.

Though we can maybe tweak the delay, I think throttling event timing breaking users expectation like #8108 is not completely avoidable. Maybe we can mention this in the doc?

Comment on lines +164 to +165
await new Promise(resolve => setTimeout(resolve, 150))
console.log("Test running!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this order is flipped, then can onUserConsoleLog often appear before onTestCaseReady?

          console.log("Test running!")
          await new Promise(resolve => setTimeout(resolve, 150))

Copy link
Member Author

@AriPerkkio AriPerkkio Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's mentioned on the PR description, this part:

Note:

  • As onUserConsoleLog is not throttled, it's still possible that reporters see test case's console logs before onTestCaseReady, if logs happen 100ms within the start.

So on the test runner thread side, the test case's console.log happens after test-prepare is called. It's reported to the main thread in different order since onUserConsoleLog is not handled by onTaskUpdate.

@sheremet-va sheremet-va merged commit 7bd11a9 into vitest-dev:main Jun 9, 2025
14 checks passed
@AriPerkkio AriPerkkio deleted the fix/runner-task-update-timing branch June 9, 2025 11:07
@AriPerkkio AriPerkkio mentioned this pull request Jun 11, 2025
6 tasks
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.

OnTestCaseReady's timing not firing as Expected
3 participants