Skip to content

Commit 0fdaa01

Browse files
authored
Merge pull request #51 from taskbadger/maintenance
chore: bump dev tooling and CLI deps
2 parents 26bb53e + 123239b commit 0fdaa01

3 files changed

Lines changed: 112 additions & 42 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_language_version:
33
python: python3.12
44
repos:
55
- repo: https://github.com/astral-sh/ruff-pre-commit
6-
rev: v0.15.12
6+
rev: v0.15.20
77
hooks:
88
- id: ruff-check
99
args: [ --fix ]

tests/test_celery.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import logging
12+
import time
1213
from unittest import mock
1314

1415
import celery
@@ -21,6 +22,18 @@
2122
from tests.utils import task_for_test
2223

2324

25+
def _wait_for_call_count(mock_obj, expected, timeout=10.0):
26+
"""Wait until ``mock_obj`` has been called ``expected`` times.
27+
28+
The worker's ``task_success`` signal fires asynchronously, so the final
29+
status update can lag behind ``result.get()`` returning. Poll for it while
30+
the mock patch is still active to avoid a race with the ``with`` block exit.
31+
"""
32+
deadline = time.monotonic() + timeout
33+
while mock_obj.call_count < expected and time.monotonic() < deadline:
34+
time.sleep(0.01)
35+
36+
2437
@pytest.fixture(autouse=True)
2538
def _check_log_errors(caplog):
2639
yield
@@ -52,6 +65,7 @@ def add_normal(self, a, b):
5265
assert result.taskbadger_task_id == tb_task.id
5366
assert result.get_taskbadger_task() is not None
5467
assert result.get(timeout=10, propagate=True) == 4
68+
_wait_for_call_count(update, 2)
5569

5670
create.assert_called_once()
5771
assert get_task.call_count == 2
@@ -416,6 +430,7 @@ def task_map_fn(self, a):
416430
create.return_value = tb_task
417431
result = map_canvas.delay()
418432
assert result.get(timeout=10, propagate=True) == [0, 2, 4, 6, 8]
433+
_wait_for_call_count(update, 2)
419434

420435
# Map operation should create one TaskBadger task
421436
assert create.call_count == 1
@@ -449,6 +464,7 @@ def task_starmap_fn(self, a, b):
449464
create.return_value = tb_task
450465
result = starmap_canvas.delay()
451466
assert result.get(timeout=10, propagate=True) == [3, 7, 11]
467+
_wait_for_call_count(update, 2)
452468

453469
# Starmap operation should create one TaskBadger task
454470
assert create.call_count == 1
@@ -482,6 +498,7 @@ def task_chunks_fn(self, a):
482498
create.return_value = tb_task
483499
result = chunks_canvas.delay()
484500
assert result.get(timeout=10, propagate=True) == [[0, 2], [4, 6], [8, 10]]
501+
_wait_for_call_count(update, 6)
485502

486503
# Each chunk should create a TaskBadger task (3 chunks of 2)
487504
assert create.call_count == 3

0 commit comments

Comments
 (0)