Skip to content

Fix the flaky worker integration tests - #1502

Merged
doc-han merged 5 commits into
mainfrom
fix-integration-test-ports
Aug 14, 2026
Merged

Fix the flaky worker integration tests#1502
doc-han merged 5 commits into
mainfrom
fix-integration-test-ports

Conversation

@elias-ba

@elias-ba elias-ba commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Makes the worker integration tests pass reliably. Closes #1501.

That job was failing at random - a different Node version each run, and the same tree giving different results across reruns. It turned out to be four separate bugs, all in the tests rather than the worker:

Ports were guessed. Servers were started on a random number between 2000 and 3000 with no check that it was free. A run makes around a dozen of those picks, so collisions happened every few runs. That was the EADDRINUSE :::2492 we kept seeing. Ports now come from a counter.

The worker wasn't connected yet. initWorker handed the server back before it had connected to Lightning - it fetches the collections version over http first, then opens the socket. Seven tests swap the worker out and queue a run straight afterwards, so the run could sit in the queue with nothing listening, hanging the file until ava's timeout. It now waits for the socket.

The sigterm test raced its own signal. It failed if a claim already in flight arrived after we sent the signal, which the worker can't help. It now keys off the worker reporting that it received it.

A lost listener in the exit reason tests. The helper every test there goes through listened with a plain once and checked the run id inside the callback, so a completion for any other run consumed the listener without resolving - hanging that promise for good. It now uses the mock's onSocketEvent, which only releases on an id match.

The four fixes are separate commits, worth reading individually.

Validation steps

  1. The three integration jobs should pass, and keep passing on reruns.
  2. cd integration-tests/worker && pnpm test locally.

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just want to know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our Responsible AI Policy

The tests picked a port at random from a thousand wide range and started
a server on it, without checking the number was free. There are around a
dozen of those picks in a run, so two of them landing on the same number
happened often enough to fail the job every few runs: the second server
couldn't bind, its setup hook never finished, and the whole file sat
pending until the two minute timeout.

The files run one at a time and each is its own process, so handing out
ports from a counter is enough. This also removes the three files that
all hardcoded 4321, which was harmless while the files run serially but
would bite anyone who turned on concurrency later.

Closes #1501
@github-project-automation github-project-automation Bot moved this to New Issues in Core Aug 14, 2026
@elias-ba
elias-ba requested a review from doc-han August 14, 2026 15:26

@doc-han doc-han left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

looks just fine

Comment thread integration-tests/worker/src/init.ts Outdated
Two more causes of the intermittent failures, both in the tests.

The worker server is handed back before it has connected to Lightning -
it fetches the collections version over http first and only then opens
the socket. Several tests swap the worker out and queue a run straight
afterwards, so the run could end up sitting in the queue with nothing
listening, and the file would hang until the timeout. That's the four
pending tests we kept seeing in the integration file. Waiting for the
socket to come up removes the race for every test at once.

The sigterm test failed whenever a claim already in flight arrived after
we sent the signal, which the worker can't do anything about. It now
keys off the worker telling us it received the signal instead.
The helper every test in that file goes through listened with a plain
once and then checked the run id inside the callback. Any completion for
another run - a late one from the previous test, or a duplicate - used up
the listener without resolving, so the promise hung for good and the
rest of the file never ran.

The mock already has onSocketEvent for exactly this: it only releases the
listener once the id matches.
@elias-ba elias-ba changed the title Stop the worker integration tests guessing port numbers Fix the flaky worker integration tests Aug 14, 2026
@doc-han
doc-han merged commit 661530c into main Aug 14, 2026
10 checks passed
@github-project-automation github-project-automation Bot moved this from New Issues to Done in Core Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Worker integration tests fail at random

4 participants