turbo-tasks: make scope_unbounded worker churn test deterministic (#100515)
### What? Makes the turbo-tasks test `scope_unbounded::tests::test_unbounded_busy_queue_does_not_churn_workers` deterministic, and tightens its worker-lifetime bound from 16 to 4. ### Why? The test failed intermittently with errors like `a saturated queue should not churn drainers, got 20 lifetimes for 20000 items`. The calling thread enqueued trivial items one at a time while the scope workers drained them immediately. If the producer was preempted for longer than `WORKER_IDLE_TIMEOUT` (100µs), the workers idled out and the next enqueue respawned them. Under CPU load this exceeded the loose bound in about 1 of 5 runs. The old shape also didn't prove much: with the idle timeout set to 0 it still usually passed. ### How? The test still processes 20,000 items, but the queue is now kept saturated by construction rather than by out-racing the scheduler: - **Parents.** Half the items are seeded as parents. Each parent waits until the seed iterator is exhausted, so no worker can sit on an empty queue while the producer is still seeding. - **Children.** Each parent spawns one child, so a worker that exits too early will be re-armed by a later `spawn`. - **Child gate.** Children wait until every parent's `spawn` call has returned. The queue is FIFO, so all parents are already in flight by then and the wait cannot deadlock. While any `spawn` is still pending, no drainer can find the queue empty. With this, a correct implementation has at most 4 accumulator lifetimes: 3 scope workers plus the calling thread. The test now checks that workers are not torn down while work is queued. It no longer measures the exact idle timeout, which can't be asserted without depending on scheduler timing. Verification: - On an 8-vCPU Linux machine: 100/100 runs idle and 100/100 runs with 8 busy-loop processes. More stress runs also passed (300/300 under 8 busy-loop processes, 400/400 across 4 concurrent test loops under 16). - Mutation check: making scope workers exit after each item makes the test fail with thousands of lifetimes (2,940 in the recorded run). - All `scope_unbounded` tests pass, and `cargo fmt --check` and `cargo clippy -p turbo-tasks --tests -- -D warnings` are clean. <!-- NEXT_JS_LLM --> <!-- fleet 8bf6a21a-27a8-41a9-bb36-ee50675a54d6 --> Co-authored-by:vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by:
Tobias Koppers <1365881+sokra@users.noreply.github.com>
Showing
Please
register
or
sign in
to comment