Keep simulated Ctrl+C inside the interrupt tests #2427
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 595 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.382
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #2427"
general
weight: 0.35
pylaterreur
What
----
The interrupt tests in
tests/test_Wakeable.py, and two intests/test_ShareConsumer.py, start a thread that calls_thread.interrupt_main()after a fixed delay, and expect theKeyboardInterruptinside atry/exceptaround the blocking call. When the call returns first, or the thread wakes up late, theKeyboardInterruptis raised later: in cleanup, in another test, or in pytest itself, which then aborts the whole session. This happened in the first CI run of #2416 on the macOS x64 agent (job): pytest stopped withKeyboardInterruptat<frozen posixpath>:457after 16 tests oftest_Wakeable.py, and the rerun passed.The 17th test,
test_can_be_interrupted[producer-poll], never interruptedpoll(). Its producer hasbootstrap.servers: localhost:9092, and with no broker there,Producer.poll()returns 1 or 2 within a few milliseconds, as soon as it has served the "connection refused" error. The test only passed because the interrupt landed in the 0.2 ssleepof itsfinallyblock; an interrupt more than about 0.1 s late escaped.This adds
TestUtils.interrupt_main_after(delay), a context manager for the blocking call. Leaving the block waits for the interrupt, so theKeyboardInterruptis always raised inside the block; a call that returns before it is interrupted fails withAssertionError: Not interrupted: ...instead. All 23 simulated interrupts use it. The producer intest_can_be_interruptedno longer setsbootstrap.servers, like the producers of the other interrupt tests, sopoll()blocks until it is interrupted, and the sleeps that waited for late interrupts are gone. The two 1 s polls interrupted after 0.4 s get the 2 s timeout of the others, so an interrupt can be up to 1.4 s late everywhere (4.6 s intest_ShareConsumer.py).Checklist
------------------
- No, tests only.
- Test-only change; see below for how it was checked.
References
----------
KeyboardInterruptat<frozen posixpath>:457after the same 16 tests oftest_Wakeable.py: https://confluentinc.semaphoreci.com/jobs/04d2d52e-aecf-402f-8c9d-6274e3e56078Test & Review
------------
test_can_be_interrupted[producer-poll]on master, traced outside pytest (Python 3.11.16):poll()returned after 1 to 6 ms in all 11 runs, 8 of them under a 10% CPU quota, and the interrupt was always caught by thefinallysleep. On this branch, with only the context manager and the old producer config, the test fails every time withAssertionError: Not interrupted: the block ended before the interrupt sent after 0.1s.TestUtils.send_sigint_after_delay(), running all 27 interrupt tests (Python 3.11.16, Linux x86_64):- master, 0.3 s late: all 4 runs broken.
test_can_be_interrupted[producer-poll]failed in 3, and 1 run aborted withKeyboardInterruptinobj.close()of the next test, after "1 failed, 16 passed", as in CI.- this branch, 0.3 s late: 4 runs, all passed. In 4 more runs made while the full unit suite ran in parallel, one failed an elapsed-time bound:
poll(timeout=1.0)took 2.51 s intest_calculate_chunk_timeout_utility_function[consumer].- this branch, 1.0 s late: 2 runs, all passed.
- this branch, 2.0 s late, beyond the 1.4 s margin: the 11 tests that interrupt a call with a finite timeout fail with
AssertionError: Not interrupted: ..., the other 16 pass, and the session runs to the end.test_can_be_interruptedunder a 5% CPU quota with 500 ms periods. Throttled threads wake together, and the interrupting thread, which wakes first, also runs first.test_can_be_interruptedpasses 30 runs out of 30 under the 5% CPU quota.tools/style-format.shon the changed files andflake8pass.Open questions / Follow-ups
--------------------------
poll(timeout=1.0)returning within 2 s. Those bounds can still fail on a loaded machine; this PR does not change them.🤖 Generated with Claude Code
https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN