|
8 | 8 | import subprocess |
9 | 9 | import sys |
10 | 10 | import textwrap |
| 11 | +import time |
11 | 12 | from contextlib import nullcontext |
12 | 13 | from pathlib import Path, PurePath, PurePosixPath |
13 | 14 |
|
@@ -138,33 +139,39 @@ def test_cwd(container_engine): |
138 | 139 | assert container.call(["pwd"], capture_output=True, cwd="/opt") == "/opt\n" |
139 | 140 |
|
140 | 141 |
|
141 | | -@pytest.mark.skipif( |
142 | | - pm == "s390x" and detect_ci_provider() == CIProvider.travis_ci, |
143 | | - reason="test is flaky on this platform, see https://github.com/pypa/cibuildwheel/pull/1961#issuecomment-2334678966", |
144 | | -) |
145 | 142 | def test_container_removed(container_engine): |
| 143 | + # test is flaky on some platforms, implement retry for 5 second |
| 144 | + timeout = 50 # * 100 ms = 5s |
146 | 145 | with OCIContainer( |
147 | 146 | engine=container_engine, image=DEFAULT_IMAGE, oci_platform=DEFAULT_OCI_PLATFORM |
148 | 147 | ) as container: |
| 148 | + assert container.name is not None |
| 149 | + container_name = container.name |
| 150 | + for _ in range(timeout): |
| 151 | + docker_containers_listing = subprocess.run( |
| 152 | + f"{container.engine.name} container ls", |
| 153 | + shell=True, |
| 154 | + check=True, |
| 155 | + stdout=subprocess.PIPE, |
| 156 | + text=True, |
| 157 | + ).stdout |
| 158 | + if container_name in docker_containers_listing: |
| 159 | + break |
| 160 | + time.sleep(0.1) |
| 161 | + assert container_name in docker_containers_listing |
| 162 | + |
| 163 | + for _ in range(timeout): |
149 | 164 | docker_containers_listing = subprocess.run( |
150 | 165 | f"{container.engine.name} container ls", |
151 | 166 | shell=True, |
152 | 167 | check=True, |
153 | 168 | stdout=subprocess.PIPE, |
154 | 169 | text=True, |
155 | 170 | ).stdout |
156 | | - assert container.name is not None |
157 | | - assert container.name in docker_containers_listing |
158 | | - old_container_name = container.name |
159 | | - |
160 | | - docker_containers_listing = subprocess.run( |
161 | | - f"{container.engine.name} container ls", |
162 | | - shell=True, |
163 | | - check=True, |
164 | | - stdout=subprocess.PIPE, |
165 | | - text=True, |
166 | | - ).stdout |
167 | | - assert old_container_name not in docker_containers_listing |
| 171 | + if container_name not in docker_containers_listing: |
| 172 | + break |
| 173 | + time.sleep(0.1) |
| 174 | + assert container_name not in docker_containers_listing |
168 | 175 |
|
169 | 176 |
|
170 | 177 | def test_large_environment(container_engine): |
|
0 commit comments