diff --git a/src/pytest_celery/api/base.py b/src/pytest_celery/api/base.py index 8475ae96..75a0a6a3 100644 --- a/src/pytest_celery/api/base.py +++ b/src/pytest_celery/api/base.py @@ -37,6 +37,9 @@ def logs(self) -> str: def name(self) -> str: return self.container.name + def hostname(self) -> str: + return self.container.id[:12] + def kill(self) -> None: self.container.kill() diff --git a/src/pytest_celery/vendors/worker/defaults.py b/src/pytest_celery/vendors/worker/defaults.py index c3b4d542..fc115033 100644 --- a/src/pytest_celery/vendors/worker/defaults.py +++ b/src/pytest_celery/vendors/worker/defaults.py @@ -4,7 +4,7 @@ WORKER_CELERY_APP_NAME = "celery_test_app" WORKER_CELERY_VERSION = "" # latest from pypi WORKER_LOG_LEVEL = "INFO" -WORKER_NAME = CELERY_SETUP_WORKER +WORKER_NAME = "celery_test_worker" WORKER_QUEUE = "celery" WORKER_ENV = { "CELERY_BROKER_URL": "memory://", diff --git a/tests/integration/api/test_worker.py b/tests/integration/api/test_worker.py index b14d877d..c1751f0c 100644 --- a/tests/integration/api/test_worker.py +++ b/tests/integration/api/test_worker.py @@ -7,6 +7,7 @@ from pytest_celery import CeleryTestWorker from pytest_celery import CeleryWorkerCluster from pytest_celery import CeleryWorkerContainer +from tests.integration.conftest import IntegrationWorkerContainer @pytest.mark.parametrize("node", [lazy_fixture(CELERY_WORKER)]) @@ -20,6 +21,10 @@ def test_app(self, node: CeleryTestWorker, celery_setup_app: Celery): def test_version(self, node: CeleryTestWorker): assert node.version == CeleryWorkerContainer.version() + def test_wait_for_log(self, node: CeleryTestWorker): + log = f"{IntegrationWorkerContainer.worker_name()}@{node.hostname()} v{node.version}" + node.wait_for_log(log, "test_celey_test_worker.test_wait_for_log") + @pytest.mark.parametrize("cluster", [lazy_fixture(CELERY_WORKER_CLUSTER)]) class test_celery_worker_cluster: diff --git a/tests/integration/vendors/test_worker.py b/tests/integration/vendors/test_worker.py index 26469934..2609aff1 100644 --- a/tests/integration/vendors/test_worker.py +++ b/tests/integration/vendors/test_worker.py @@ -6,6 +6,7 @@ from pytest_celery import CeleryTestWorker from pytest_celery import CeleryWorkerContainer from tests.defaults import ALL_WORKERS_FIXTURES +from tests.integration.conftest import IntegrationWorkerContainer @pytest.mark.parametrize("container", lazy_fixture(ALL_WORKERS_FIXTURES)) @@ -22,3 +23,7 @@ def test_ready(self, node: CeleryTestWorker): def test_app(self, node: CeleryTestWorker, celery_setup_app: Celery): assert node.app is celery_setup_app + + def test_wait_for_log(self, node: CeleryTestWorker): + log = f"{IntegrationWorkerContainer.worker_name()}@{node.hostname()} v{node.version}" + node.wait_for_log(log, "test_base_test_worker.test_wait_for_log") diff --git a/tests/unit/api/test_worker.py b/tests/unit/api/test_worker.py index 65cbee6d..2d3f201c 100644 --- a/tests/unit/api/test_worker.py +++ b/tests/unit/api/test_worker.py @@ -26,6 +26,10 @@ def test_version(self, unit_tests_container: CeleryTestContainer, celery_setup_a node = CeleryTestWorker(unit_tests_container, celery_setup_app) assert node.version == "unknown" + def test_wait_for_log(self, unit_tests_container: CeleryTestContainer, celery_setup_app: Celery): + node = CeleryTestWorker(unit_tests_container, celery_setup_app) + node.wait_for_log("", "test_celey_test_worker.test_wait_for_log") + class test_celery_worker_cluster: def test_ready( diff --git a/tests/unit/vendors/test_worker.py b/tests/unit/vendors/test_worker.py index 0b3b6400..e9e7c0db 100644 --- a/tests/unit/vendors/test_worker.py +++ b/tests/unit/vendors/test_worker.py @@ -7,6 +7,7 @@ from pytest_celery import WORKER_ENV from pytest_celery import CeleryTestWorker from pytest_celery import CeleryWorkerContainer +from tests.unit.docker.api import UnitWorkerContainer class test_celery_worker_container: @@ -54,3 +55,7 @@ def test_ready(self, celery_setup_worker: CeleryTestWorker): def test_app(self, celery_setup_worker: CeleryTestWorker, celery_setup_app: Celery): assert celery_setup_worker.app is celery_setup_app + + def test_wait_for_log(self, celery_setup_worker: CeleryTestWorker): + log = f"{UnitWorkerContainer.worker_name()}@{celery_setup_worker.hostname()} v{celery_setup_worker.version}" + celery_setup_worker.wait_for_log(log, "test_base_test_worker.test_wait_for_log")