fix(test): implement retry for test_container_removed
The test is flaky on some platforms. Implement retry rather than just skip.
This commit is contained in:
@@ -8,6 +8,7 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import time
|
||||||
from contextlib import nullcontext
|
from contextlib import nullcontext
|
||||||
from pathlib import Path, PurePath, PurePosixPath
|
from pathlib import Path, PurePath, PurePosixPath
|
||||||
|
|
||||||
@@ -138,25 +139,15 @@ def test_cwd(container_engine):
|
|||||||
assert container.call(["pwd"], capture_output=True, cwd="/opt") == "/opt\n"
|
assert container.call(["pwd"], capture_output=True, cwd="/opt") == "/opt\n"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
|
||||||
pm == "s390x" and detect_ci_provider() == CIProvider.travis_ci,
|
|
||||||
reason="test is flaky on this platform, see https://github.com/pypa/cibuildwheel/pull/1961#issuecomment-2334678966",
|
|
||||||
)
|
|
||||||
def test_container_removed(container_engine):
|
def test_container_removed(container_engine):
|
||||||
|
# test is flaky on some platforms, implement retry for 5 second
|
||||||
|
timeout = 50 # * 100 ms = 5s
|
||||||
with OCIContainer(
|
with OCIContainer(
|
||||||
engine=container_engine, image=DEFAULT_IMAGE, oci_platform=DEFAULT_OCI_PLATFORM
|
engine=container_engine, image=DEFAULT_IMAGE, oci_platform=DEFAULT_OCI_PLATFORM
|
||||||
) as container:
|
) as container:
|
||||||
docker_containers_listing = subprocess.run(
|
|
||||||
f"{container.engine.name} container ls",
|
|
||||||
shell=True,
|
|
||||||
check=True,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
text=True,
|
|
||||||
).stdout
|
|
||||||
assert container.name is not None
|
assert container.name is not None
|
||||||
assert container.name in docker_containers_listing
|
container_name = container.name
|
||||||
old_container_name = container.name
|
for _ in range(timeout):
|
||||||
|
|
||||||
docker_containers_listing = subprocess.run(
|
docker_containers_listing = subprocess.run(
|
||||||
f"{container.engine.name} container ls",
|
f"{container.engine.name} container ls",
|
||||||
shell=True,
|
shell=True,
|
||||||
@@ -164,7 +155,23 @@ def test_container_removed(container_engine):
|
|||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
text=True,
|
text=True,
|
||||||
).stdout
|
).stdout
|
||||||
assert old_container_name not in docker_containers_listing
|
if container_name in docker_containers_listing:
|
||||||
|
break
|
||||||
|
time.sleep(0.1)
|
||||||
|
assert container_name in docker_containers_listing
|
||||||
|
|
||||||
|
for _ in range(timeout):
|
||||||
|
docker_containers_listing = subprocess.run(
|
||||||
|
f"{container.engine.name} container ls",
|
||||||
|
shell=True,
|
||||||
|
check=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
).stdout
|
||||||
|
if container_name not in docker_containers_listing:
|
||||||
|
break
|
||||||
|
time.sleep(0.1)
|
||||||
|
assert container_name not in docker_containers_listing
|
||||||
|
|
||||||
|
|
||||||
def test_large_environment(container_engine):
|
def test_large_environment(container_engine):
|
||||||
|
|||||||
Reference in New Issue
Block a user