qwen-code/scripts/tests/event-loop-yield.test.js
qwen-code-dev-bot 38c5f9b4fd
fix(ci): yield the event loop between script tests to avoid vitest RPC timeouts (#10037) (#10050)
* fix(ci): yield the event loop between script tests to avoid vitest RPC timeouts (#10037)

The v0.22.1 release quality job exited 1 on `npm run test:scripts` with
every test green. vitest's worker->main `onTaskUpdate` RPC has a fixed 60s
timeout; the synchronous spawnSync-driven script suites keep a forked
worker's event loop blocked for an entire file (~66s on the heaviest
suite), so the queued RPC response is never processed before the timer
fires, surfacing as an unhandled `[vitest-worker]: Timeout calling
"onTaskUpdate"` error. Linux keeps unhandled errors fatal (the scripts
vitest config only exempts non-Linux since #9728), so the release died.

Add a global per-test event-loop yield to the scripts test setup. The
timer is captured at setup load so `vi.useFakeTimers()` inside a test
cannot intercept the yield. Any continuous stall is now bounded by a
single test, so RPC responses drain long before the 60s deadline. Real
test failures stay fatal on every platform; the Linux unhandled-error
signal is untouched.

* fix(ci): state the actual yield invariant in the script test setup comment (#10037)

* test(ci): pin the script-test event-loop yield invariant (#10037)

---------

Co-authored-by: qwen-code-dev-bot <qwen-code-dev-bot@users.noreply.github.com>
Co-authored-by: Shaojin Wen <shaojin.wensj@alibaba-inc.com>
2026-08-26 07:11:15 +00:00

25 lines
795 B
JavaScript

/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/
import { expect, it } from 'vitest';
// Pins the invariant established by test-setup.ts's beforeEach yield:
// between two tests the worker's event loop must turn far enough to drain
// pending macrotasks. Without that yield a fully synchronous file never
// reaches the timer phase between tests, the flag armed below never flips,
// and the same unbroken stall is what lets vitest's fixed 60s worker->main
// `onTaskUpdate` RPC timeout fire (see test-setup.ts).
let macrotaskRan = false;
it('arms a flag from a real macrotask callback', () => {
setTimeout(() => {
macrotaskRan = true;
}, 0);
});
it('observes the event loop turned between tests', () => {
expect(macrotaskRan).toBe(true);
});