WIP: Remove all provider wait lines

This commit is contained in:
Alex Pyrgiotis 2024-10-03 14:30:13 +03:00
parent e749e92425
commit 130ba92e34
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA
3 changed files with 4 additions and 63 deletions

View file

@ -21,31 +21,6 @@ def provider() -> Container:
return Container()
class ContainerWait(Container):
"""Container isolation provider that blocks until the container has started."""
def exec_container(self, *args, **kwargs): # type: ignore [no-untyped-def]
# Check every 100ms if a container with the expected name has showed up.
# Else, closing the file descriptors may not work.
name = kwargs["name"]
runtime = self.get_runtime()
p = super().exec_container(*args, **kwargs)
for i in range(50):
containers = subprocess.run(
[runtime, "ps"], capture_output=True
).stdout.decode()
if name in containers:
return p
time.sleep(0.1)
raise RuntimeError(f"Container {name} did not start within 5 seconds")
@pytest.fixture
def provider_wait() -> ContainerWait:
return ContainerWait()
class TestContainer(IsolationProviderTest):
pass

View file

@ -1,11 +1,9 @@
import os
import subprocess
import pytest
from pytest_mock import MockerFixture
from dangerzone.conversion import errors
from dangerzone.document import Document
from dangerzone.isolation_provider.base import IsolationProvider
from dangerzone.isolation_provider.dummy import Dummy
@ -16,24 +14,6 @@ if not os.environ.get("DUMMY_CONVERSION", False):
pytest.skip("Dummy conversion is not enabled", allow_module_level=True)
class DummyWait(Dummy):
"""Dummy isolation provider that spawns a blocking process."""
def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen:
return subprocess.Popen(
["python3"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
start_new_session=True,
)
@pytest.fixture
def provider_wait() -> DummyWait:
return DummyWait()
@pytest.fixture
def provider() -> Dummy:
return Dummy()
@ -42,21 +22,12 @@ def provider() -> Dummy:
class TestDummyTermination(IsolationProviderTermination):
def test_failed(
self,
provider_wait: IsolationProvider,
provider: IsolationProvider,
mocker: MockerFixture,
) -> None:
mocker.patch.object(
provider_wait,
provider,
"get_proc_exception",
return_value=errors.DocFormatUnsupported(),
)
super().test_failed(provider_wait, mocker)
def test_linger_unkillable(
self,
provider_wait: IsolationProvider,
mocker: MockerFixture,
) -> None:
# We have to spawn a blocking process here, else we can't imitate an
# "unkillable" process.
super().test_linger_unkillable(provider_wait, mocker)
super().test_failed(provider, mocker)

View file

@ -20,11 +20,6 @@ elif os.environ.get("DUMMY_CONVERSION", False):
pytest.skip("Dummy conversion is enabled", allow_module_level=True)
@pytest.fixture
def provider() -> Qubes:
return Qubes()
class QubesWait(Qubes):
"""Qubes isolation provider that blocks until the disposable qube has started."""
@ -53,7 +48,7 @@ class QubesWait(Qubes):
@pytest.fixture
def provider_wait() -> QubesWait:
def provider() -> QubesWait:
return QubesWait()