Skip to content

Commit 1959fce

Browse files
fix(tests): make test_get_platform less flaky (#26)
1 parent ae0e0af commit 1959fce

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

tests/test_client.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import sys
88
import json
9+
import time
910
import asyncio
1011
import inspect
1112
import subprocess
@@ -1635,10 +1636,20 @@ async def test_main() -> None:
16351636
[sys.executable, "-c", test_code],
16361637
text=True,
16371638
) as process:
1638-
try:
1639-
process.wait(2)
1640-
if process.returncode:
1641-
raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code")
1642-
except subprocess.TimeoutExpired as e:
1643-
process.kill()
1644-
raise AssertionError("calling get_platform using asyncify resulted in a hung process") from e
1639+
timeout = 10 # seconds
1640+
1641+
start_time = time.monotonic()
1642+
while True:
1643+
return_code = process.poll()
1644+
if return_code is not None:
1645+
if return_code != 0:
1646+
raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code")
1647+
1648+
# success
1649+
break
1650+
1651+
if time.monotonic() - start_time > timeout:
1652+
process.kill()
1653+
raise AssertionError("calling get_platform using asyncify resulted in a hung process")
1654+
1655+
time.sleep(0.1)

0 commit comments

Comments
 (0)