Skip to content

Commit

Permalink
fix(test): implement retry for test_container_removed
Browse files Browse the repository at this point in the history
The test is flaky on some platforms. Implement retry rather than just skip.
  • Loading branch information
mayeut authored and henryiii committed Feb 25, 2025
1 parent 55037e9 commit ee23dd1
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions unit_test/oci_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import subprocess
import sys
import textwrap
import time
from contextlib import nullcontext
from pathlib import Path, PurePath, PurePosixPath

Expand Down Expand Up @@ -138,33 +139,39 @@ def test_cwd(container_engine):
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):
# test is flaky on some platforms, implement retry for 5 second
timeout = 50 # * 100 ms = 5s
with OCIContainer(
engine=container_engine, image=DEFAULT_IMAGE, oci_platform=DEFAULT_OCI_PLATFORM
) as container:
assert container.name is not None
container_name = container.name
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 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
assert container.name is not None
assert container.name in docker_containers_listing
old_container_name = container.name

docker_containers_listing = subprocess.run(
f"{container.engine.name} container ls",
shell=True,
check=True,
stdout=subprocess.PIPE,
text=True,
).stdout
assert old_container_name not in docker_containers_listing
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):
Expand Down

0 comments on commit ee23dd1

Please # to comment.