Skip to content

Commit e34c122

Browse files
committed
test: assert exactly one capture loss line per failed batch
1 parent 4486b42 commit e34c122

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎posthog/test/test_async_client.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,14 @@ async def test_failed_capture_logs_one_loss_line_without_response_detail(
844844
await client.shutdown()
845845

846846
assert "server-secret" not in caplog.text
847-
assert f"1 event(s) not persisted by {path}: APIError (status=400)" in caplog.text
847+
loss_lines = [
848+
r.getMessage()
849+
for r in caplog.records
850+
if "event(s) not persisted by" in r.getMessage()
851+
]
852+
assert loss_lines == [
853+
f"[PostHog] 1 event(s) not persisted by {path}: APIError (status=400)"
854+
]
848855

849856

850857
@pytest.mark.asyncio

‎posthog/test/test_client.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,9 +2789,14 @@ def test_sync_send_failure_without_on_error_logs_aggregate_line(
27892789

27902790
self.assertIsNone(result)
27912791
output = "\n".join(logs.output)
2792-
self.assertIn(
2793-
f"1 event(s) not persisted by {path}: APIError (status=400)",
2794-
output,
2792+
loss_lines = [
2793+
r.getMessage()
2794+
for r in logs.records
2795+
if "event(s) not persisted by" in r.getMessage()
2796+
]
2797+
self.assertEqual(
2798+
loss_lines,
2799+
[f"[PostHog] 1 event(s) not persisted by {path}: APIError (status=400)"],
27952800
)
27962801
self.assertNotIn("server-secret", output)
27972802

0 commit comments

Comments
 (0)