Skip to content

Commit 69aa2b6

Browse files
Fix intermittent 500 errors on GET /ping endpoint
Root cause: The /ping endpoint contained artificial error injection code that raised an Exception whenever int(time.time()) % 3 == 0, causing 500 errors approximately once every 3 seconds. Changes: - Removed error injection logic from /ping endpoint in app/main.py - Added test_ping() to verify endpoint returns 200 with correct response - Added test_ping_reliability() to test endpoint stability across multiple calls All tests passing (3/3). The /ping endpoint now returns stable responses under continuous polling.
1 parent 12f5d2d commit 69aa2b6

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

app/main.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212

1313
@app.get("/ping")
1414
def test():
15-
if int(time.time()) % 3 == 0:
16-
raise Exception("unknown internal error")
17-
1815
return {"pong": True}
1916

2017
@app.get("/hello")

app/test_main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,17 @@
77
def test_read_root():
88
response = client.get("/")
99
assert response.status_code == 200
10+
11+
def test_ping():
12+
"""Test that /ping endpoint returns 200 and correct response"""
13+
response = client.get("/ping")
14+
assert response.status_code == 200
15+
assert response.json() == {"pong": True}
16+
17+
def test_ping_reliability():
18+
"""Test that /ping endpoint is reliable across multiple calls"""
19+
# Test multiple times to ensure no intermittent failures
20+
for _ in range(10):
21+
response = client.get("/ping")
22+
assert response.status_code == 200
23+
assert response.json() == {"pong": True}

0 commit comments

Comments
 (0)