@@ -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" )),
@@ -40,31 +46,31 @@ def db_config(self):
4046 "database" : os .getenv ("POSTGRES_DATABASE" , "postgres" ),
4147 "workspace" : os .getenv ("POSTGRES_WORKSPACE" , "test_retry" ),
4248 "max_connections" : int (os .getenv ("POSTGRES_MAX_CONNECTIONS" , "10" )),
43- # Connection retry configuration
49+ # Connection retry configuration - mirrors postgres_impl.py ClientManager.get_config()
50+ # NEW DEFAULTS optimized for HA deployments
4451 "connection_retry_attempts" : min (
45- 10 , int (os .getenv ("POSTGRES_CONNECTION_RETRIES" , "3" ))
52+ 100 ,
53+ int (os .getenv ("POSTGRES_CONNECTION_RETRIES" , "10" )), # 3 → 10
4654 ),
4755 "connection_retry_backoff" : min (
48- 5.0 , float (os .getenv ("POSTGRES_CONNECTION_RETRY_BACKOFF" , "0.5" ))
56+ 300.0 ,
57+ float (
58+ os .getenv ("POSTGRES_CONNECTION_RETRY_BACKOFF" , "3.0" )
59+ ), # 0.5 → 3.0
4960 ),
5061 "connection_retry_backoff_max" : min (
51- 60.0 , float (os .getenv ("POSTGRES_CONNECTION_RETRY_BACKOFF_MAX" , "5.0" ))
62+ 600.0 ,
63+ float (
64+ os .getenv ("POSTGRES_CONNECTION_RETRY_BACKOFF_MAX" , "30.0" )
65+ ), # 5.0 → 30.0
5266 ),
5367 "pool_close_timeout" : min (
5468 30.0 , float (os .getenv ("POSTGRES_POOL_CLOSE_TIMEOUT" , "5.0" ))
5569 ),
5670 }
5771
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-
6672 @pytest .mark .asyncio
67- async def test_real_connection_success (self , db_config , test_env ):
73+ async def test_real_connection_success (self , db_config ):
6874 """
6975 Test successful connection to real PostgreSQL database.
7076
@@ -100,11 +106,12 @@ async def test_real_connection_success(self, db_config, test_env):
100106 await db .pool .close ()
101107
102108 @pytest .mark .asyncio
103- async def test_simulated_transient_error_with_real_db (self , db_config , test_env ):
109+ async def test_simulated_transient_error_with_real_db (self , db_config ):
104110 """
105111 Test retry mechanism with simulated transient errors on real database.
106112
107113 Simulates connection failures on first 2 attempts, then succeeds.
114+ Uses new HA defaults (10 retries, 3s backoff).
108115 """
109116 print ("\n " + "=" * 80 )
110117 print ("INTEGRATION TEST 2: Simulated Transient Errors" )
@@ -155,12 +162,13 @@ async def mock_create_pool_with_failures(*args, **kwargs):
155162 await db .pool .close ()
156163
157164 @pytest .mark .asyncio
158- async def test_query_retry_with_real_db (self , db_config , test_env ):
165+ async def test_query_retry_with_real_db (self , db_config ):
159166 """
160167 Test query-level retry with simulated connection issues.
161168
162169 Tests that queries retry on transient failures by simulating
163170 a temporary database unavailability.
171+ Uses new HA defaults (10 retries, 3s backoff).
164172 """
165173 print ("\n " + "=" * 80 )
166174 print ("INTEGRATION TEST 3: Query-Level Retry" )
@@ -193,11 +201,12 @@ async def test_query_retry_with_real_db(self, db_config, test_env):
193201 await db .pool .close ()
194202
195203 @pytest .mark .asyncio
196- async def test_concurrent_queries_with_real_db (self , db_config , test_env ):
204+ async def test_concurrent_queries_with_real_db (self , db_config ):
197205 """
198206 Test concurrent queries to validate thread safety and connection pooling.
199207
200208 Runs multiple concurrent queries to ensure no deadlocks or race conditions.
209+ Uses new HA defaults (10 retries, 3s backoff).
201210 """
202211 print ("\n " + "=" * 80 )
203212 print ("INTEGRATION TEST 4: Concurrent Queries" )
@@ -243,9 +252,10 @@ async def run_query(query_id):
243252 await db .pool .close ()
244253
245254 @pytest .mark .asyncio
246- async def test_pool_close_timeout_real (self , db_config , test_env ):
255+ async def test_pool_close_timeout_real (self , db_config ):
247256 """
248257 Test pool close timeout protection with real database.
258+ Uses new HA defaults (10 retries, 3s backoff).
249259 """
250260 print ("\n " + "=" * 80 )
251261 print ("INTEGRATION TEST 5: Pool Close Timeout" )
0 commit comments