Skip to content

Commit

Permalink
Fixed bug in CeleryTestWorker.hostname()
Browse files Browse the repository at this point in the history
  • Loading branch information
Nusnus committed Dec 12, 2023
1 parent a0bdd88 commit 49331d9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
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_name(self) -> str:
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
6 changes: 6 additions & 0 deletions tests/integration/api/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ 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}"
worker.wait_for_log(log, "test_celey_test_worker.test_wait_for_log")
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

0 comments on commit 49331d9

Please sign in to comment.