Skip to content

Commit adb4eac

Browse files
committed
Update Postgres integration tests to use new HA retry defaults
- Increase retry count to 10 - Raise initial backoff to 3.0s - Raise max backoff to 30.0s - Remove obsolete test_env fixture - Align tests with HA config
1 parent 484e441 commit adb4eac

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

tests/test_postgres_retry_integration.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ class TestPostgresRetryIntegration:
3131

3232
@pytest.fixture
3333
def db_config(self):
34-
"""Load database configuration from environment variables."""
34+
"""Load database configuration from environment variables.
35+
36+
Uses new HA-optimized defaults that match postgres_impl.py ClientManager.get_config():
37+
- 10 retry attempts (up from 3)
38+
- 3.0s initial backoff (up from 0.5s)
39+
- 30.0s max backoff (up from 5.0s)
40+
"""
3541
return {
3642
"host": os.getenv("POSTGRES_HOST", "localhost"),
3743
"port": int(os.getenv("POSTGRES_PORT", "5432")),
@@ -41,30 +47,23 @@ def db_config(self):
4147
"workspace": os.getenv("POSTGRES_WORKSPACE", "test_retry"),
4248
"max_connections": int(os.getenv("POSTGRES_MAX_CONNECTIONS", "10")),
4349
# Connection retry configuration - mirrors postgres_impl.py ClientManager.get_config()
50+
# NEW DEFAULTS optimized for HA deployments
4451
"connection_retry_attempts": min(
45-
100, int(os.getenv("POSTGRES_CONNECTION_RETRIES", "3"))
52+
100, int(os.getenv("POSTGRES_CONNECTION_RETRIES", "10")) # 3 → 10
4653
),
4754
"connection_retry_backoff": min(
48-
300.0, float(os.getenv("POSTGRES_CONNECTION_RETRY_BACKOFF", "0.5"))
55+
300.0, float(os.getenv("POSTGRES_CONNECTION_RETRY_BACKOFF", "3.0")) # 0.5 → 3.0
4956
),
5057
"connection_retry_backoff_max": min(
51-
600.0, float(os.getenv("POSTGRES_CONNECTION_RETRY_BACKOFF_MAX", "5.0"))
58+
600.0, float(os.getenv("POSTGRES_CONNECTION_RETRY_BACKOFF_MAX", "30.0")) # 5.0 → 30.0
5259
),
5360
"pool_close_timeout": min(
5461
30.0, float(os.getenv("POSTGRES_POOL_CLOSE_TIMEOUT", "5.0"))
5562
),
5663
}
5764

58-
@pytest.fixture
59-
def test_env(self, monkeypatch):
60-
"""Set up test environment variables for retry configuration."""
61-
monkeypatch.setenv("POSTGRES_CONNECTION_RETRIES", "3")
62-
monkeypatch.setenv("POSTGRES_CONNECTION_RETRY_BACKOFF", "0.5")
63-
monkeypatch.setenv("POSTGRES_CONNECTION_RETRY_BACKOFF_MAX", "2.0")
64-
monkeypatch.setenv("POSTGRES_POOL_CLOSE_TIMEOUT", "3.0")
65-
6665
@pytest.mark.asyncio
67-
async def test_real_connection_success(self, db_config, test_env):
66+
async def test_real_connection_success(self, db_config):
6867
"""
6968
Test successful connection to real PostgreSQL database.
7069
@@ -100,11 +99,12 @@ async def test_real_connection_success(self, db_config, test_env):
10099
await db.pool.close()
101100

102101
@pytest.mark.asyncio
103-
async def test_simulated_transient_error_with_real_db(self, db_config, test_env):
102+
async def test_simulated_transient_error_with_real_db(self, db_config):
104103
"""
105104
Test retry mechanism with simulated transient errors on real database.
106105
107106
Simulates connection failures on first 2 attempts, then succeeds.
107+
Uses new HA defaults (10 retries, 3s backoff).
108108
"""
109109
print("\n" + "=" * 80)
110110
print("INTEGRATION TEST 2: Simulated Transient Errors")
@@ -155,12 +155,13 @@ async def mock_create_pool_with_failures(*args, **kwargs):
155155
await db.pool.close()
156156

157157
@pytest.mark.asyncio
158-
async def test_query_retry_with_real_db(self, db_config, test_env):
158+
async def test_query_retry_with_real_db(self, db_config):
159159
"""
160160
Test query-level retry with simulated connection issues.
161161
162162
Tests that queries retry on transient failures by simulating
163163
a temporary database unavailability.
164+
Uses new HA defaults (10 retries, 3s backoff).
164165
"""
165166
print("\n" + "=" * 80)
166167
print("INTEGRATION TEST 3: Query-Level Retry")
@@ -193,11 +194,12 @@ async def test_query_retry_with_real_db(self, db_config, test_env):
193194
await db.pool.close()
194195

195196
@pytest.mark.asyncio
196-
async def test_concurrent_queries_with_real_db(self, db_config, test_env):
197+
async def test_concurrent_queries_with_real_db(self, db_config):
197198
"""
198199
Test concurrent queries to validate thread safety and connection pooling.
199200
200201
Runs multiple concurrent queries to ensure no deadlocks or race conditions.
202+
Uses new HA defaults (10 retries, 3s backoff).
201203
"""
202204
print("\n" + "=" * 80)
203205
print("INTEGRATION TEST 4: Concurrent Queries")
@@ -243,9 +245,10 @@ async def run_query(query_id):
243245
await db.pool.close()
244246

245247
@pytest.mark.asyncio
246-
async def test_pool_close_timeout_real(self, db_config, test_env):
248+
async def test_pool_close_timeout_real(self, db_config):
247249
"""
248250
Test pool close timeout protection with real database.
251+
Uses new HA defaults (10 retries, 3s backoff).
249252
"""
250253
print("\n" + "=" * 80)
251254
print("INTEGRATION TEST 5: Pool Close Timeout")

0 commit comments

Comments
 (0)