Skip to content

Commit bc7ca86

Browse files
authored
Simplify celery double patching test (#4626)
just check double patching, no need to recurse 10000 times part of #4623
1 parent 69d65db commit bc7ca86

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

tests/integrations/celery/test_celery.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,34 @@ def dummy_task(x, y):
246246
]
247247

248248

249-
def test_no_stackoverflows(celery):
250-
"""We used to have a bug in the Celery integration where its monkeypatching
249+
def test_no_double_patching(celery):
250+
"""Ensure that Celery tasks are only patched once to prevent stack overflows.
251+
252+
We used to have a bug in the Celery integration where its monkeypatching
251253
was repeated for every task invocation, leading to stackoverflows.
252254
253255
See https://github.com/getsentry/sentry-python/issues/265
254256
"""
255257

256-
results = []
257-
258258
@celery.task(name="dummy_task")
259259
def dummy_task():
260-
sentry_sdk.get_isolation_scope().set_tag("foo", "bar")
261-
results.append(42)
260+
return 42
262261

263-
for _ in range(10000):
264-
dummy_task.delay()
262+
# Initially, the task should not be marked as patched
263+
assert not hasattr(dummy_task, "_sentry_is_patched")
264+
265+
# First invocation should trigger patching
266+
result1 = dummy_task.delay()
267+
assert result1.get() == 42
268+
assert getattr(dummy_task, "_sentry_is_patched", False) is True
269+
270+
patched_run = dummy_task.run
265271

266-
assert results == [42] * 10000
267-
assert not sentry_sdk.get_isolation_scope()._tags
272+
# Second invocation should not re-patch
273+
result2 = dummy_task.delay()
274+
assert result2.get() == 42
275+
assert dummy_task.run is patched_run
276+
assert getattr(dummy_task, "_sentry_is_patched", False) is True
268277

269278

270279
def test_simple_no_propagation(capture_events, init_celery):

0 commit comments

Comments
 (0)