Skip to content

Commit

Permalink
fix: add ulimit support for dragonfly
Browse files Browse the repository at this point in the history
  • Loading branch information
cofin committed Jan 16, 2025
1 parent dccdc5f commit db514be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 2 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ extra-dependencies = [
"pytest-vcr",
"pytest-click",
"pytest-xdist",
"pytest-sugar",
# lint
"mypy",
"ruff",
Expand Down Expand Up @@ -471,14 +472,7 @@ module = ["docutils.nodes.*"]

[[tool.mypy.overrides]]
ignore_missing_imports = true
module = [
"pyodbc",
"google.auth.*",
"google.cloud.*",
"google.protobuf.*",
"googleapiclient",
"googleapiclient.*",
]
module = ["pyodbc", "google.auth.*", "google.cloud.*", "google.protobuf.*", "googleapiclient", "googleapiclient.*"]

[tool.ruff]
exclude = [
Expand Down
4 changes: 4 additions & 0 deletions src/pytest_databases/_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import docker
from docker.errors import ImageNotFound
from docker.types import Ulimit
from pytest_databases.helpers import get_xdist_worker_id
from pytest_databases.types import ServiceContainer

Expand Down Expand Up @@ -128,6 +129,8 @@ def run(
timeout: int = 10,
pause: float = 0.1,
transient: bool = False,
ulimits: list[Ulimit] | None = None,
shm_size: int | None = None,
) -> Generator[ServiceContainer, None, None]:
if check is None and wait_for_log is None:
msg = "Must set at least check or wait_for_log"
Expand All @@ -152,6 +155,7 @@ def run(
labels=["pytest_databases"],
name=name,
environment=env,
ulimits=ulimits,
)
container.reload()

Expand Down
8 changes: 8 additions & 0 deletions src/pytest_databases/docker/dragonfly.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import redis
from redis.exceptions import ConnectionError as RedisConnectionError

from docker.types import Ulimit
from pytest_databases.helpers import get_xdist_worker_num
from pytest_databases.types import ServiceContainer, XdistIsolationLevel

Expand Down Expand Up @@ -49,11 +50,17 @@ def dragonfly_image() -> str:
return "docker.dragonflydb.io/dragonflydb/dragonfly"


@pytest.fixture(scope="session")
def dragonfly_ulimits() -> list[Ulimit]:
return [Ulimit(name="memlock", soft=-1, hard=-1)]


@pytest.fixture(autouse=False, scope="session")
def dragonfly_service(
docker_service: DockerService,
dragonfly_image: str,
xdist_dragonfly_isolation_level: XdistIsolationLevel,
dragonfly_ulimits: list[Ulimit],
) -> Generator[DragonflyService, None, None]:
worker_num = get_xdist_worker_num()
if xdist_dragonfly_isolation_level == "database":
Expand All @@ -69,5 +76,6 @@ def dragonfly_service(
container_port=6379,
name=name,
transient=xdist_dragonfly_isolation_level == "server",
ulimits=dragonfly_ulimits,
) as service:
yield DragonflyService(host=service.host, port=service.port, db=db)

0 comments on commit db514be

Please sign in to comment.