Skip to content

Commit

Permalink
test: additional testcase for reusable containers
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasschaub committed Jul 3, 2024
1 parent 18bd825 commit 580469f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion core/tests/test_reusable_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_docker_container_reuse_default():
def test_docker_container_with_reuse_reuse_disabled():
with DockerContainer("hello-world").with_reuse() as container:
assert container._reuse == True
assert testcontainers_config.tc_properties_testcontainers_reuse_enable == False
id = container._container.id
wait_for_logs(container, "Hello from Docker!")
containers = DockerClient().client.containers.list(all=True)
Expand All @@ -30,6 +31,7 @@ def test_docker_container_with_reuse_reuse_disabled():
def test_docker_container_with_reuse_reuse_enabled_ryuk_enabled(monkeypatch):
# Make sure Ryuk cleanup is not active from previous test runs
Reaper.delete_instance()

tc_properties_mock = testcontainers_config.tc_properties | {"testcontainers.reuse.enable": "true"}
monkeypatch.setattr(testcontainers_config, "tc_properties", tc_properties_mock)
monkeypatch.setattr(testcontainers_config, "ryuk_reconnection_timeout", "0.1s")
Expand All @@ -52,11 +54,12 @@ def test_docker_container_with_reuse_reuse_enabled_ryuk_enabled(monkeypatch):
def test_docker_container_with_reuse_reuse_enabled_ryuk_disabled(monkeypatch):
# Make sure Ryuk cleanup is not active from previous test runs
Reaper.delete_instance()

tc_properties_mock = testcontainers_config.tc_properties | {"testcontainers.reuse.enable": "true"}
monkeypatch.setattr(testcontainers_config, "tc_properties", tc_properties_mock)
monkeypatch.setattr(testcontainers_config, "ryuk_disabled", True)

with DockerContainer("hello-world").with_reuse() as container:
assert container._reuse == True
id = container._container.id
wait_for_logs(container, "Hello from Docker!")
containers = DockerClient().client.containers.list(all=True)
Expand All @@ -65,6 +68,22 @@ def test_docker_container_with_reuse_reuse_enabled_ryuk_disabled(monkeypatch):
container._container.remove(force=True)


def test_docker_container_with_reuse_reuse_enabled_ryuk_disabled_same_id(monkeypatch):
# Make sure Ryuk cleanup is not active from previous test runs
Reaper.delete_instance()

tc_properties_mock = testcontainers_config.tc_properties | {"testcontainers.reuse.enable": "true"}
monkeypatch.setattr(testcontainers_config, "tc_properties", tc_properties_mock)
monkeypatch.setattr(testcontainers_config, "ryuk_disabled", True)

with DockerContainer("hello-world").with_reuse() as container:
id = container._container.id
with DockerContainer("hello-world").with_reuse() as container:
assert id == container._container.id
# Cleanup after keeping container alive (with_reuse)
container._container.remove(force=True)


def test_docker_container_labels_hash():
expected_hash = "91fde3c09244e1d3ec6f18a225b9261396b9a1cb0f6365b39b9795782817c128"
with DockerContainer("hello-world").with_reuse() as container:
Expand Down

0 comments on commit 580469f

Please sign in to comment.