Skip to content

test: end a hung test run after 5 minutes and print every stack - #2134

Draft
moetemp wants to merge 1 commit into
mainfrom
moe/test-hang-watchdog
Draft

moetemp wants to merge 1 commit into
mainfrom
moe/test-hang-watchdog

Conversation

@moetemp

@moetemp moetemp commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

What changed?

This PR adds a watchdog to the tests. If one test with its fixtures takes more than 300 s, the process prints the stack of every thread and exits, and xdist reports that test as crashed. The limit is the new ini option test_hang_limit.

Why?

A CI test step hangs now and then until its 20 minute limit, with no hint of which test it was. pytest-timeout can't end such a hang. It covers only the test call (timeout_func_only), and its signal can't stop a main thread that is blocked in native code. The watchdog uses faulthandler.dump_traceback_later, which runs on a C thread.

It doesn't fix the hang. It makes the next one short and shows where it sits.

One point is open. The 300 s also count the session setup of the first test, with the download of the dev server.

How did you test it?

A test with a fixture teardown that sleeps hung the run before the change. With -o test_hang_limit=10 the run ends in 12 s, with the stack at the line that hangs and the name of the test. The whole suite passes on the local dev server and on the time-skipping server.

Link to a test plan if any -

  • Unit Tests
  • Staging
  • End to End Tests

pytest-timeout covers only the test call and can't stop a main thread blocked outside Python, so
one hang stalled a CI step for 20 minutes. The new timer dumps every stack and ends the process,
and xdist then names the test that hung.
@moetemp moetemp added the skip-changelog PR changes do not require changelog updates label Nov 15, 2026

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