Skip to content

Commit d244f2c

Browse files
fix: resolve flaky tests across platforms and Python versions, appearing on main branch (#649)
* fix: update test parameter for collate_requests to improve test reliability * fix: increase wait time in test_worker_restart_and_server_shutdown for macOS compatibility * fix: update concurrency cancel-in-progress condition for pull requests * test with skip test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add timeout to these fn * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 21f7686 commit d244f2c

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

.github/workflows/ci-testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI testing
22

33
concurrency:
44
group: ${{ github.workflow }}-${{ github.ref }}
5-
cancel-in-progress: true
5+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
66

77
on:
88
push:

tests/unit/test_batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def test_batched_loop():
248248
pytest.param(0, 1000),
249249
pytest.param(0.1, 2),
250250
pytest.param(1000, 2),
251-
pytest.param(0.1, 1000),
251+
pytest.param(0.5, 1000),
252252
],
253253
)
254254
def test_collate_requests(batch_timeout, batch_size):

tests/unit/test_lit_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,8 @@ async def test_worker_restart_and_server_shutdown():
773773
resp = await ac.post("/predict", json={"input": 0}, timeout=2)
774774
assert resp.status_code == 500
775775

776-
await asyncio.sleep(2)
776+
# Increased wait time for macOS where process spawning is slower
777+
await asyncio.sleep(5 if sys.platform == "darwin" else 2)
777778

778779
tasks = []
779780
for _ in range(50):

tests/unit/test_loops.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ def test_run_single_loop_with_async(async_loop_args, monkeypatch):
173173
with contextlib.suppress(KeyboardInterrupt):
174174
loop._run_single_loop_with_async(lit_api_mock, requests_queue, mock_transport, NOOP_CB_RUNNER)
175175

176-
response = asyncio.get_event_loop().run_until_complete(mock_transport.areceive(consumer_id=0))
176+
response = asyncio.run(mock_transport.areceive(consumer_id=0))
177177
assert response == ("uuid-123", ((), "START", ls.utils.LoopResponseType.REGULAR, ANY))
178-
response = asyncio.get_event_loop().run_until_complete(mock_transport.areceive(consumer_id=0))
178+
response = asyncio.run(mock_transport.areceive(consumer_id=0))
179179
assert response == ("uuid-123", ({"output": 1}, ls.utils.LitAPIStatus.OK, ls.utils.LoopResponseType.REGULAR, ANY))
180-
response = asyncio.get_event_loop().run_until_complete(mock_transport.areceive(consumer_id=1))
180+
response = asyncio.run(mock_transport.areceive(consumer_id=1))
181181
assert response == ("uuid-234", ((), "START", ls.utils.LoopResponseType.REGULAR, ANY))
182-
response = asyncio.get_event_loop().run_until_complete(mock_transport.areceive(consumer_id=1))
182+
response = asyncio.run(mock_transport.areceive(consumer_id=1))
183183
assert response == ("uuid-234", ({"output": 4}, ls.utils.LitAPIStatus.OK, ls.utils.LoopResponseType.REGULAR, ANY))
184184

185185

@@ -292,7 +292,7 @@ def test_run_streaming_loop_with_async(mock_transport, monkeypatch):
292292
loop.run_streaming_loop_async(lit_api, requests_queue, mock_transport, NOOP_CB_RUNNER)
293293

294294
for i in range(6):
295-
response = asyncio.get_event_loop().run_until_complete(mock_transport.areceive(consumer_id=0))
295+
response = asyncio.run(mock_transport.areceive(consumer_id=0))
296296
if i == 0:
297297
assert response == (
298298
"uuid-123",

0 commit comments

Comments
 (0)