d
This commit is contained in:
34
domain-api/tests/test_core_db_retry.py
Normal file
34
domain-api/tests/test_core_db_retry.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from psycopg2 import errors
|
||||
|
||||
from app.core.db import db_read_retry
|
||||
|
||||
|
||||
def test_db_read_retry_retries_retryable_error_once() -> None:
|
||||
attempts = {"count": 0}
|
||||
|
||||
@db_read_retry(attempts=3, initial_delay_seconds=0)
|
||||
def flaky() -> str:
|
||||
attempts["count"] += 1
|
||||
if attempts["count"] == 1:
|
||||
raise errors.DeadlockDetected()
|
||||
return "ok"
|
||||
|
||||
assert flaky() == "ok"
|
||||
assert attempts["count"] == 2
|
||||
|
||||
|
||||
def test_db_read_retry_does_not_swallow_non_retryable_error() -> None:
|
||||
attempts = {"count": 0}
|
||||
|
||||
@db_read_retry(attempts=3, initial_delay_seconds=0)
|
||||
def broken() -> str:
|
||||
attempts["count"] += 1
|
||||
raise ValueError("boom")
|
||||
|
||||
try:
|
||||
broken()
|
||||
except ValueError as exc:
|
||||
assert str(exc) == "boom"
|
||||
else:
|
||||
raise AssertionError("expected ValueError")
|
||||
assert attempts["count"] == 1
|
||||
Reference in New Issue
Block a user