Skip to content

tests: fix flaky reckless tests by waiting for the canned github server#9306

Open
ksedgwic wants to merge 1 commit into
ElementsProject:masterfrom
ksedgwic:fix-flaky-reckless-server-race
Open

tests: fix flaky reckless tests by waiting for the canned github server#9306
ksedgwic wants to merge 1 commit into
ElementsProject:masterfrom
ksedgwic:fix-flaky-reckless-server-race

Conversation

@ksedgwic

Copy link
Copy Markdown
Collaborator

Observed on a CI run for #9286 (Valgrind Test CLN 1/12, test_search):
https://github.com/ElementsProject/lightning/actions/runs/29122024616/job/86461830290

The canned_github_server fixture starts a Flask server with Popen and
never waits for it to listen; the git repository setup between the
Popen and the yield usually gives it enough time. Under CI load it
can lose that race: in the failure above, test_search's first
reckless invocation got connection refused within a second of the
test starting, and Flask's "Running on http://127.0.0.1:39495"
banner only appears in the log after the test had already failed
(so the server did come up and bind its port -- just too late).

The fix waits for the port to accept connections before yielding, and
fails loudly if the server process dies instead of coming up.

Changelog-None

@ksedgwic ksedgwic mentioned this pull request Jul 13, 2026

@Andezion Andezion 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 good to me! pyln.testing.utils.wait_for() already implements this poll-with-backoff pattern elsewhere in the suite - so could reuse it here instead of a hand-rolled loop?(though the custom loop works fine as-is!!)

Comment thread tests/test_reckless.py
# first reckless invocation doesn't race it and get connection refused.
start = time.time()
while True:
assert server.poll() is None, "canned github server died"

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.

Nice!

The canned_github_server fixture Popens a Flask server and never
waits for it to start listening; the git repository setup between the
Popen and the yield usually gives it enough time.  Under CI load it
can lose that race: a valgrind-shard failure shows test_search's
first reckless invocation getting connection refused within a second
of the test starting, while Flask's "Running on http://127.0.0.1:..."
banner only appears in the log after the test had already failed.

Wait for the port to accept connections before yielding, and fail
loudly if the server process dies instead of coming up.

Changelog-None
@Andezion
Andezion force-pushed the fix-flaky-reckless-server-race branch from 4dbffb8 to 13cc9a2 Compare July 16, 2026 23:20
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.

2 participants