Skip to content

Commit

Permalink
Added unit & integration tests for CeleryTestWorker.wait_for_log() (#58)
Browse files Browse the repository at this point in the history
* Added test_wait_for_log() to unit tests

* Added test_wait_for_log() to integration tests

* Set default worker name to celery_test_worker
  • Loading branch information
Nusnus authored Oct 13, 2023
1 parent d33c685 commit 7aa0a57
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/pytest_celery/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/pytest_celery/vendors/worker/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://",
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/api/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand All @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/vendors/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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")
4 changes: 4 additions & 0 deletions tests/unit/api/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/vendors/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")

0 comments on commit 7aa0a57

Please sign in to comment.