New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
celery_worker pytest fixture timeouts since celery 5.0.3 #6521
Comments
hahaha I just created a reproducible example to submit this! You actually don’t even need any test body: pytest_plugins = ['celery.contrib.pytest']
def test_worker_initializes(celery_worker):
assert True |
Have you tried using |
Yes, that’s why the title says “since celery 5.0.3”. Bug was introduced in e203168, which went into 5.0.3. Since pytest just hangs after the timeout, I just used the $ cat >test_worker.py <<EOF
pytest_plugins = ['celery.contrib.pytest']
def test_worker_initializes(celery_worker):
assert True
EOF
$ git bisect start
$ git bisect good v5.0.2
$ git bisect bad v5.0.3
$ git bisect run timeout 10s pytest -q test_worker.py
...
e2031688284484d5b5a57ba29cd9cae2d9a81e39 is the first bad commit
...
$ git bisect reset |
@matusvalo Any chance you can handle this? |
FYI, it seems the issue is caused by this specific change; e203168#diff-acf0d4c4ddf0742d0699b98f51eec8823d1f22e7b76d0b4eb6f42ab27100188cL1193-R1214 Hope that it will help |
I will check that ASAP. |
I did basic investigation and it seems that the problem is connected to
And that's the reason why this issue was not found by test suite of Celery. |
OK. I understand the root cause of the issue. The problem was in cache+memory:// result back-end. This back-end is supposed to share peace of memory and pass the results using this memory - see: celery/celery/backends/cache.py Lines 53 to 83 in a192f9c
But the problem is that this peace of code is not global and hence it was shared only since result back-end was global. This was changed e203168#diff-acf0d4c4ddf0742d0699b98f51eec8823d1f22e7b76d0b4eb6f42ab27100188cL1193-R1214 and hence broke this result back-end. (for clarity see the line celery/celery/backends/cache.py Line 82 in a192f9c
DummyCache class). The fix is easy: Just create global instance of DummyCache class and use it as client. The fix should look like this:
class DummyClient:
def __init__(self, *args, **kwargs):
self.cache = LRUCache(limit=5000)
def get(self, key, *args, **kwargs):
return self.cache.get(key)
def get_multi(self, keys):
cache = self.cache
return {k: cache[k] for k in keys if k in cache}
def set(self, key, value, *args, **kwargs):
self.cache[key] = value
def delete(self, key, *args, **kwargs):
self.cache.pop(key, None)
def incr(self, key, delta=1):
return self.cache.incr(key, delta)
def touch(self, key, expire):
pass
def __call__(self, *args, **kwargs):
return self
DUMMY_CLIENT = DummyClient()
backends = {
'memcache': get_best_memcache,
'memcached': get_best_memcache,
'pylibmc': get_best_memcache,
'memory': lambda: (DUMMY_CLIENT, ensure_bytes),
} I have tested the fix and seems to be working. I will create the PR later on. |
This adapts the celery requirements to the last known where our builds are fine. Currently, 5.0.3 got released and this ends up making all the swh modules relying on tasks timeout. A bug upstream is opened [1]. In the mean time, this workaround fixes [2] and most probably the remaining swh builds. [1] celery/celery#6521 [2] https://jenkins.softwareheritage.org/job/DSCH/job/tests/1132/console
@flying-sheep @anlambert See the PR with the fix: #6524. Could you recheck it? |
I may release 5.0.4 with just this fix. |
PR works flawlessly, thank you! |
Would really appreciate it! |
I'm on it. |
I'm on celery 5.1.2, I'm facing the same issue in a little bit of a different manner. When I run this, pytest_plugins = ["celery.contrib.pytest"]
def test_worker_initializes(celery_app, celery_worker):
assert True it works perfectly fine. However, if I add import pytest
pytest_plugins = ["celery.contrib.pytest"]
@pytest.fixture(scope='session')
def celery_worker_parameters():
return {
'queues': ('default'),
# 'perform_ping_check': False
}
def test_worker_initializes(celery_worker):
assert True A quick workaround that I found was setting |
This is probably something else. Are your broker and backend available before you run the test suite? |
Were you able to resolve this issue? I'm also facing the same issue with celery 5.2.7 |
Since the 5.0.3 release of celery, the
celery_worker
pytest fixture leads to a timeout when performing ping check.The issue can be reproduced using this simple test file:
Below is the pytest output:
After a quick
git bisect
session, I managed to identify the commit that introduced the issue: e203168The text was updated successfully, but these errors were encountered: