Skip to content
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

Fixed bug in CeleryTestWorker.hostname() #108

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/pytest_celery/api/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
def worker_queue(self) -> str:
return self.container.worker_queue()

def hostname(self) -> str:
return f"{self.worker_name}@{super().hostname()}"

Check warning on line 35 in src/pytest_celery/api/worker.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/api/worker.py#L34-L35

Added lines #L34 - L35 were not covered by tests


class CeleryWorkerCluster(CeleryTestCluster):
def __init__(self, *workers: tuple[CeleryTestWorker | CeleryTestContainer]) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/api/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_name(self, node: CeleryTestNode):
def test_hostname(self, node: CeleryTestNode):
hostname = node.hostname()
assert isinstance(hostname, str)
assert len(hostname) == 12
assert node.container.id[:12] in hostname

@pytest.mark.parametrize("signal", [None, "SIGKILL"])
def test_kill(self, node: CeleryTestNode, signal: str | int):
Expand Down
11 changes: 8 additions & 3 deletions tests/integration/api/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pytest_celery import CeleryTestWorker
from pytest_celery import CeleryWorkerCluster
from pytest_celery import CeleryWorkerContainer
from tests.integration.conftest import IntegrationWorkerContainer


@pytest.mark.parametrize("worker", [lazy_fixture(CELERY_WORKER)])
Expand All @@ -20,12 +19,18 @@ def test_app(self, worker: CeleryTestWorker, celery_setup_app: Celery):
def test_version(self, worker: CeleryTestWorker):
assert worker.version == CeleryWorkerContainer.version()

def test_hostname(self, worker: CeleryTestWorker):
hostname = worker.hostname()
assert "@" in hostname
assert worker.worker_name in hostname.split("@")[0]
assert worker.container.id[:12] in hostname.split("@")[1]

def test_wait_for_log(self, worker: CeleryTestWorker):
log = f"{IntegrationWorkerContainer.worker_name()}@{worker.hostname()} v{worker.version}"
log = f"{worker.hostname()} v{worker.version}"
worker.wait_for_log(log, "test_celey_test_worker.test_wait_for_log")

def test_assert_log_exists(self, worker: CeleryTestWorker):
log = f"{IntegrationWorkerContainer.worker_name()}@{worker.hostname()} v{worker.version}"
log = f"{worker.hostname()} v{worker.version}"
worker.assert_log_exists(log, "test_celey_test_worker.test_assert_log_exists")


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/api/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_name(self, node: CeleryTestNode):
assert node.name()

def test_hostname(self, node: CeleryTestNode):
assert node.hostname()
assert node.container.id[:12] in node.hostname()

def test_kill(self, node: CeleryTestNode):
node.kill()
Expand Down