Skip to content

test: remove races from the Worker and Workflow tests - #2133

Open
moetemp wants to merge 4 commits into
mainfrom
moe/fix-flaky-worker-shutdown-tests
Open

moetemp wants to merge 4 commits into
mainfrom
moe/fix-flaky-worker-shutdown-tests

Conversation

@moetemp

@moetemp moetemp commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What changed?

This PR removes races from the Worker and Workflow tests.

  • The tests that change the current deployment version wait until the routing change reached the task queues. The helper for that wait returned after one call.
  • Two child-cancel tests use a child that only a cancel ends, and one of them waits until the parent holds its child.
  • The test dev server gets a long poll expiration of 5 s (matching.longPollExpirationInterval).

Why?

Each one is a flaky test in CI.

  • test_worker_with_worker_deployment_config fails in cloud-test. Its Workflow starts before the new current version is routed.
  • test_workflow_cancel_multi and test_workflow_cancel_child_started fail on the time-skipping server. It skips the child's 1000 s sleep, and the cancel Signal can arrive before the parent holds the child.

test_warns_when_workers_too_low and test_worker_fatal_error_with time out when the server misses a poll that comes right after ShutdownWorker. The Worker then waits until that poll expires, about a minute by default. The fix for that is in the server (temporalio/temporal#13116). The shorter expiration only keeps such a shutdown fast in the tests, and it doesn't apply to cloud-test.

How did you test it?

For the child-cancel tests I reproduced each cause on its own, and each test fails before the change and passes after. The routing race shows only against Temporal Cloud, so the cloud-test job is its check.

Link to a test plan if any -

  • Unit Tests
  • Staging
  • End to End Tests

@moetemp moetemp added the skip-changelog PR changes do not require changelog updates label Nov 15, 2026
@moetemp moetemp changed the title test: wait until a Worker polls before its shutdown in the Worker tests test: wait for Worker polls and for routing propagation in the Worker tests Nov 15, 2026
@moetemp moetemp changed the title test: wait for Worker polls and for routing propagation in the Worker tests test: remove races from the Worker and Workflow tests Nov 15, 2026
@moetemp
moetemp marked this pull request as ready for review November 16, 2026 04:34
@moetemp
moetemp requested a review from a team as a code owner November 16, 2026 04:34
The propagation helper returned a bool to `assert_eventually`, which only retries on an assertion,
so it never waited. Five tests also started a Workflow right after setting the current version,
when the task queue could still route to the old one.
On the time-skipping server the child inherits time skipping, so its 1000 s sleep fires about a
second after it starts. The child now waits on a condition that only a cancel ends.
A Signal that shares a Workflow Task with the child's start runs its handler before `run` resumes,
so the handler found no child yet. The test waited only for the child to exist.
@moetemp
moetemp force-pushed the moe/fix-flaky-worker-shutdown-tests branch from c570a44 to 78a6bbb Compare November 16, 2026 17:14
The server can miss a poll that comes right after `ShutdownWorker`. The Worker then waits
until that poll expires, about a minute by default, and the test times out.
moetemp added a commit to temporalio/temporal that referenced this pull request Nov 17, 2026
…k queue (#13116)

## What changed?
This PR makes matching record a Worker as shut down before the poll
cancellation fan-out, so that a poll that arrives later is refused at
once.

Fixes #13114

## Why?
A Worker that shuts down right after its start can send `ShutdownWorker`
while its first poll is still on its way. Matching skips the fan-out
when the root partition isn't loaded, and it didn't record the Worker in
`shutdownWorkers`. The late poll was then accepted and stayed open for
50 to 60 seconds. An SDK that waits for the server to end its polls took
that long to shut down.

Related: temporalio/sdk-rust#1802 and temporalio/sdk-python#2133.

## How did you test it?
- [x] built
- [ ] run locally and tested manually
- [ ] covered by existing tests
- [x] added new unit test(s)
- [x] added new functional test(s)

Both new tests shut a Worker down for an unloaded task queue and then
poll with the same key. In the functional test the poll took 59.9s
without the fix, and 0.06s with it.

## Potential risks
`shutdownWorkers` is local to each matching host. So a poll that lands
on a partition of another host is still accepted. One matching host, as
in the dev server, is fully covered.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog PR changes do not require changelog updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant