-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ryuk): Enable Ryuk test suite. Ryuk image 0.5.1 -> 0.7.0. Add RYU…
…K_RECONNECTION_TIMEOUT env variable (#509) - Re-enables the Ryuk test suite - Bumps Ryuk container image from 0.5.1 - > 0.7.0 - Add env variable `RYUK_RECONNECTION_TIMEOUT` (As documented in the [official Ryuk repo](https://github.com/testcontainers/moby-ryuk?tab=readme-ov-file#ryuk-configuration))
- Loading branch information
Showing
5 changed files
with
64 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,58 @@ | ||
from contextlib import contextmanager | ||
|
||
from time import sleep | ||
import pytest | ||
from pytest import MonkeyPatch | ||
|
||
from docker import DockerClient | ||
from docker.errors import NotFound | ||
|
||
from testcontainers.core import container | ||
from testcontainers.core import container as container_module | ||
from testcontainers.core.container import Reaper | ||
from testcontainers.core.container import DockerContainer | ||
from testcontainers.core.waiting_utils import wait_for_logs | ||
|
||
|
||
@pytest.mark.skip("invalid test - ryuk logs 'Removed' right before exiting") | ||
def test_wait_for_reaper(): | ||
def test_wait_for_reaper(monkeypatch: MonkeyPatch): | ||
Reaper.delete_instance() | ||
monkeypatch.setattr(container_module, "RYUK_RECONNECTION_TIMEOUT", "0.1s") | ||
docker_client = DockerClient() | ||
container = DockerContainer("hello-world").start() | ||
|
||
container_id = container.get_wrapped_container().short_id | ||
reaper_id = Reaper._container.get_wrapped_container().short_id | ||
|
||
assert docker_client.containers.get(container_id) is not None | ||
assert docker_client.containers.get(reaper_id) is not None | ||
|
||
wait_for_logs(container, "Hello from Docker!") | ||
|
||
assert Reaper._socket is not None | ||
Reaper._socket.close() | ||
|
||
assert Reaper._container is not None | ||
wait_for_logs(Reaper._container, r".* Removed \d .*", timeout=30) | ||
sleep(0.6) # Sleep until Ryuk reaps all dangling containers. 0.5 extra seconds for good measure. | ||
|
||
with pytest.raises(NotFound): | ||
docker_client.containers.get(container_id) | ||
with pytest.raises(NotFound): | ||
docker_client.containers.get(reaper_id) | ||
|
||
# Cleanup Ryuk class fields after manual Ryuk shutdown | ||
Reaper.delete_instance() | ||
|
||
|
||
def test_container_without_ryuk(monkeypatch: MonkeyPatch): | ||
Reaper.delete_instance() | ||
monkeypatch.setattr(container_module, "RYUK_DISABLED", True) | ||
with DockerContainer("hello-world") as container: | ||
wait_for_logs(container, "Hello from Docker!") | ||
assert Reaper._instance is None | ||
|
||
|
||
@contextmanager | ||
def reset_reaper_instance(): | ||
old_value = Reaper._instance | ||
Reaper._instance = None | ||
yield | ||
Reaper._instance = old_value | ||
def test_ryuk_is_reused_in_same_process(): | ||
with DockerContainer("hello-world") as container: | ||
wait_for_logs(container, "Hello from Docker!") | ||
reaper_instance = Reaper._instance | ||
|
||
assert reaper_instance is not None | ||
|
||
def test_container_without_ryuk(monkeypatch): | ||
monkeypatch.setattr(container, "RYUK_DISABLED", True) | ||
with reset_reaper_instance(), DockerContainer("hello-world") as cont: | ||
wait_for_logs(cont, "Hello from Docker!") | ||
assert Reaper._instance is None | ||
with DockerContainer("hello-world") as container: | ||
wait_for_logs(container, "Hello from Docker!") | ||
assert reaper_instance is Reaper._instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters