Skip to content

Commit

Permalink
Added: default_worker_ports
Browse files Browse the repository at this point in the history
  • Loading branch information
Nusnus committed Apr 5, 2024
1 parent f574c0b commit b318a41
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/pytest_celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
from pytest_celery.vendors.worker.fixtures import default_worker_container_session_cls
from pytest_celery.vendors.worker.fixtures import default_worker_env
from pytest_celery.vendors.worker.fixtures import default_worker_initial_content
from pytest_celery.vendors.worker.fixtures import default_worker_ports

Check warning on line 106 in src/pytest_celery/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/__init__.py#L106

Added line #L106 was not covered by tests
from pytest_celery.vendors.worker.fixtures import default_worker_signals
from pytest_celery.vendors.worker.fixtures import default_worker_tasks
from pytest_celery.vendors.worker.fixtures import default_worker_utils_module
Expand Down
2 changes: 2 additions & 0 deletions src/pytest_celery/vendors/worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ ENV WORKER_QUEUE=$CELERY_WORKER_QUEUE
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

EXPOSE 5678

# Install Python dependencies
RUN pip install --no-cache-dir --upgrade \
pip \
Expand Down
6 changes: 6 additions & 0 deletions src/pytest_celery/vendors/worker/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pytest_celery.vendors.worker.defaults import DEFAULT_WORKER_ENV
from pytest_celery.vendors.worker.defaults import DEFAULT_WORKER_LOG_LEVEL
from pytest_celery.vendors.worker.defaults import DEFAULT_WORKER_NAME
from pytest_celery.vendors.worker.defaults import DEFAULT_WORKER_PORTS

Check warning on line 17 in src/pytest_celery/vendors/worker/container.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/worker/container.py#L17

Added line #L17 was not covered by tests
from pytest_celery.vendors.worker.defaults import DEFAULT_WORKER_QUEUE
from pytest_celery.vendors.worker.defaults import DEFAULT_WORKER_VERSION
from pytest_celery.vendors.worker.volume import WorkerInitialContent
Expand Down Expand Up @@ -197,3 +198,8 @@ def initial_content(
content.set_config_from_object(worker_app)

return content.generate()

@classmethod

Check warning on line 202 in src/pytest_celery/vendors/worker/container.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/worker/container.py#L202

Added line #L202 was not covered by tests
def ports(cls) -> dict | None:
"""Ports to expose from the worker container."""
return DEFAULT_WORKER_PORTS

Check warning on line 205 in src/pytest_celery/vendors/worker/container.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/worker/container.py#L205

Added line #L205 was not covered by tests
4 changes: 4 additions & 0 deletions src/pytest_celery/vendors/worker/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"PYTHONDONTWRITEBYTECODE": "1",
"PYTHONPATH": "/app",
}
WORKER_DEBUGPY_PORTS = {

Check warning on line 24 in src/pytest_celery/vendors/worker/defaults.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/worker/defaults.py#L24

Added line #L24 was not covered by tests
"5678/tcp": "5678",
}
WORKER_VOLUME = {
"bind": "/app",
"mode": "rw",
Expand All @@ -30,6 +33,7 @@
DEFAULT_WORKER_LOG_LEVEL = WORKER_LOG_LEVEL
DEFAULT_WORKER_NAME = WORKER_NAME
DEFAULT_WORKER_ENV = WORKER_ENV
DEFAULT_WORKER_PORTS = None

Check warning on line 36 in src/pytest_celery/vendors/worker/defaults.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/worker/defaults.py#L36

Added line #L36 was not covered by tests
DEFAULT_WORKER_QUEUE = WORKER_QUEUE
DEFAULT_WORKER_CONTAINER_TIMEOUT = 60
DEFAULT_WORKER_VOLUME = WORKER_VOLUME
14 changes: 14 additions & 0 deletions src/pytest_celery/vendors/worker/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def default_worker_container_session_cls() -> type[CeleryWorkerContainer]:

default_worker_container = container(
image="{celery_base_worker_image.id}",
ports=fxtr("default_worker_ports"),
environment=fxtr("default_worker_env"),
network="{default_pytest_celery_network.name}",
volumes={"{default_worker_volume.name}": DEFAULT_WORKER_VOLUME},
Expand Down Expand Up @@ -237,6 +238,19 @@ def default_worker_initial_content(
)


@pytest.fixture

Check warning on line 241 in src/pytest_celery/vendors/worker/fixtures.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/worker/fixtures.py#L241

Added line #L241 was not covered by tests
def default_worker_ports(default_worker_container_cls: type[CeleryWorkerContainer]) -> dict | None:
"""Port bindings for this vendor.
Args:
default_worker_container_cls (type[CeleryWorkerContainer]): See also: :ref:`vendor-class`.
Returns:
dict: Port bindings.
"""
return default_worker_container_cls.ports()

Check warning on line 251 in src/pytest_celery/vendors/worker/fixtures.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/worker/fixtures.py#L251

Added line #L251 was not covered by tests


@pytest.fixture
def default_worker_app_module(default_worker_container_cls: type[CeleryWorkerContainer]) -> ModuleType:
"""App module for this worker.
Expand Down
1 change: 1 addition & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def default_worker_container_session_cls() -> type[CeleryWorkerContainer]:

default_worker_container = container(
image="{integration_tests_worker_image.id}",
ports=fxtr("default_worker_ports"),
environment=fxtr("default_worker_env"),
network="{default_pytest_celery_network.name}",
volumes={"{default_worker_volume.name}": DEFAULT_WORKER_VOLUME},
Expand Down
4 changes: 3 additions & 1 deletion tests/smoke/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def worker_queue(cls) -> str:

celery_latest_worker_container = container(
image="{celery_latest_worker_image.id}",
ports=fxtr("default_worker_ports"),
environment=fxtr("default_worker_env"),
network="{default_pytest_celery_network.name}",
volumes={"{default_worker_volume.name}": DEFAULT_WORKER_VOLUME},
Expand Down Expand Up @@ -96,7 +97,8 @@ def default_worker_container_session_cls() -> type[CeleryWorkerContainer]:


default_worker_container = container(
image="{smoke_tests_worker_image.id}", # TODO: Use fixture to avoid defining default_worker_container again
image="{smoke_tests_worker_image.id}",
ports=fxtr("default_worker_ports"),
environment=fxtr("default_worker_env"),
network="{default_pytest_celery_network.name}",
volumes={"{default_worker_volume.name}": DEFAULT_WORKER_VOLUME},
Expand Down

0 comments on commit b318a41

Please sign in to comment.