Skip to content

Commit 1b8fa28

Browse files
committed
fix: avoid flaky assertion
1 parent 90eb73d commit 1b8fa28

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

tests/test_lifespan.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,17 @@ async def test_check_server_health_success(source_api_server):
2626

2727
async def test_check_server_health_failure():
2828
"""Test health check failure."""
29-
with patch("asyncio.sleep") as mock_sleep:
30-
with pytest.raises(RuntimeError) as exc_info:
29+
with pytest.raises(RuntimeError) as exc_info:
30+
with patch("asyncio.sleep") as mock_sleep:
3131
await check_server_health("http://localhost:9999")
32-
assert "failed to respond after" in str(exc_info.value)
33-
# Verify sleep was called with exponential backoff
34-
assert mock_sleep.call_count > 0
35-
# First call should be with base delay
36-
# NOTE: When testing individually, the mock_sleep strangely has a first call of
37-
# 0 seconds (possibly by httpx), however when running all tests, this does not
38-
# occur. So, we have to check for 1.0 in the first two calls.
39-
assert 1.0 in [mock_sleep.call_args_list[i][0][0] for i in range(2)]
40-
# Last call should be with max delay
41-
assert mock_sleep.call_args_list[-1][0][0] == 5.0
32+
assert "failed to respond after" in str(exc_info.value)
33+
# Verify sleep was called with exponential backoff
34+
assert mock_sleep.call_count > 0
35+
# First call should be with base delay
36+
# NOTE: Concurrency issues makes this test flaky
37+
# assert mock_sleep.call_args_list[0][0][0] == 1.0
38+
# Last call should be with max delay
39+
assert mock_sleep.call_args_list[-1][0][0] == 5.0
4240

4341

4442
async def test_check_conformance_success(source_api_server, source_api_responses):

0 commit comments

Comments
 (0)