Skip to content

Commit 0c1a0d2

Browse files
whummerclaude
andcommitted
Add connection retries to ParadeDB test helper
PostgreSQL may not be ready to accept queries immediately after the TCP port becomes reachable (Docker port forwarding opens the port before PostgreSQL finishes initialization). Retry the connection to handle this timing window. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a4d08d6 commit 0c1a0d2

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

paradedb/tests/test_extension.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
import boto3
24
import psycopg2
35
from localstack.utils.strings import short_uid
@@ -12,15 +14,21 @@
1214
DATABASE = "mydatabase"
1315

1416

15-
def get_connection():
16-
"""Create a connection to ParadeDB."""
17-
return psycopg2.connect(
18-
host=HOST,
19-
port=PORT,
20-
user=USER,
21-
password=PASSWORD,
22-
database=DATABASE,
23-
)
17+
def get_connection(retries: int = 15, sleep: float = 2.0):
18+
"""Create a connection to ParadeDB, retrying until the server is ready."""
19+
for attempt in range(retries):
20+
try:
21+
return psycopg2.connect(
22+
host=HOST,
23+
port=PORT,
24+
user=USER,
25+
password=PASSWORD,
26+
database=DATABASE,
27+
)
28+
except psycopg2.OperationalError:
29+
if attempt == retries - 1:
30+
raise
31+
time.sleep(sleep)
2432

2533

2634
def test_connect_to_paradedb():

0 commit comments

Comments
 (0)