| 1 |
import os |
| 2 |
import subprocess |
| 3 |
import time |
| 4 |
from concurrent.futures import ThreadPoolExecutor |
| 5 |
|
| 6 |
disabled_error_message = "Refusing to deserialize disabled content of type " |
| 7 |
|
| 8 |
|
| 9 |
class test_config_serialization: |
| 10 |
def test_accept(self, celery_app): |
| 11 |
app = celery_app |
| 12 |
# Redefine env to use in subprocess |
| 13 |
# broker_url and result backend are different for each integration test backend |
| 14 |
passenv = { |
| 15 |
**os.environ, |
| 16 |
"CELERY_BROKER_URL": app.conf.broker_url, |
| 17 |
"CELERY_RESULT_BACKEND": app.conf.result_backend, |
| 18 |
} |
| 19 |
with ThreadPoolExecutor(max_workers=2) as executor: |
| 20 |
f1 = executor.submit(get_worker_error_messages, "w1", passenv) |
| 21 |
f2 = executor.submit(get_worker_error_messages, "w2", passenv) |
| 22 |
time.sleep(3) |
| 23 |
log1 = f1.result() |
| 24 |
log2 = f2.result() |
| 25 |
|
| 26 |
for log in [log1, log2]: |
| 27 |
assert log.find(disabled_error_message) == -1, log |
| 28 |
|
| 29 |
|
| 30 |
def get_worker_error_messages(name, env): |
| 31 |
"""run a worker and return its stderr |
| 32 |
|
| 33 |
:param name: the name of the worker |
| 34 |
:param env: the environment to run the worker in |
| 35 |
|
| 36 |
worker must be running in other process because of avoiding conflict.""" |
| 37 |
worker = subprocess.Popen( |
| 38 |
[ |
| 39 |
"celery", |
| 40 |
"--config", |
| 41 |
"t.integration.test_serialization_config", |
| 42 |
"worker", |
| 43 |
"-c", |
| 44 |
"2", |
| 45 |
"-n", |
| 46 |
f"{name}@%%h", |
| 47 |
], |
| 48 |
stderr=subprocess.PIPE, |
| 49 |
stdout=subprocess.PIPE, |
| 50 |
env=env, |
| 51 |
) |
| 52 |
worker.terminate() |
| 53 |
err = worker.stderr.read().decode("utf-8") |
| 54 |
return err |