Skip to content

Fix flaky timeout and context availability in test_on_ready_counter_is_synchronized (#415) - #472

Merged
auvipy merged 1 commit into
celery:mainfrom
0xrutabaga:fix/issue-415-synchronized-counter-test-timeout
Oct 7, 2026
Merged

auvipy merged 1 commit into
celery:mainfrom
0xrutabaga:fix/issue-415-synchronized-counter-test-timeout

Conversation

@0xrutabaga

Copy link
Copy Markdown
Contributor

Fixes #415.

Problem

est_on_ready_counter_is_synchronized tests synchronization across start methods ['fork', 'spawn']. This suffers from two failure modes:
  1. �illiard.get_context('fork') raises KeyError: 'fork' on platforms that do not support fork (such as Windows).
  2. The asynchronous task completion uses a rigid 1-second timeout (.get(1)). Under heavy CPU load or busy CI environments, worker initialization and job execution can exceed 1 second, causing intermittent TimeoutError. Furthermore, if an assertion fails or a timeout occurs, the pool's processes were not guaranteed to be terminated and joined, causing resource leaks across subsequent tests.

Solution

  • Check whether each context is available via ctx in billiard.get_all_start_methods() before running the test on that start method.
  • Increase the wait timeout from 1 to 10 seconds, consistent with standard test timeouts across est_pool.py.
  • Wrap the pool execution and assertion in a ry...finally block ensuring pool.terminate() and pool.join() are always called.

Verification

  • Tested locally with pytest: pytest t/unit/test_pool.py -k 'test_on_ready_counter_is_synchronized' passes cleanly.

@auvipy
auvipy self-requested a review October 7, 2026 03:08
@auvipy
auvipy merged commit 10746f2 into celery:main Oct 7, 2026
9 checks passed
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.

Test test_pool.test_on_ready_counter_is_synchronized may fail if the CPU is under heavy load

2 participants