Skip to content

Commit 050fe9d

Browse files
committed
python: pin the reconnect behavior in a single test
1 parent c26a117 commit 050fe9d

1 file changed

Lines changed: 6 additions & 27 deletions

File tree

sdks/python/tests/test_connection_defaults.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,13 @@ def test_async_absurd_falls_back_to_default_absurd_uri(monkeypatch):
5050

5151

5252
class MockConnection:
53-
def __init__(self):
54-
self.broken = False
55-
self.closed = False
53+
broken = False
5654

5755
async def close(self):
58-
self.closed = True
56+
pass
5957

6058

61-
def test_async_absurd_replaces_an_interrupted_owned_connection(monkeypatch):
59+
def test_async_absurd_reconnects_only_after_an_interrupted_connection(monkeypatch):
6260
made = []
6361

6462
async def connect(dsn, autocommit=True):
@@ -71,30 +69,11 @@ async def connect(dsn, autocommit=True):
7169
async def run():
7270
await client._ensure_connected()
7371
made[0].broken = True
74-
await client._ensure_connected()
72+
await client._ensure_connected() # interrupted: replaced
73+
await client.close()
74+
await client._ensure_connected() # closed cleanly: not resurrected
7575

7676
asyncio.run(run())
7777

7878
assert len(made) == 2
7979
assert client._conn is made[1]
80-
81-
82-
def test_async_absurd_does_not_reconnect_after_an_explicit_close(monkeypatch):
83-
made = []
84-
85-
async def connect(dsn, autocommit=True):
86-
made.append(MockConnection())
87-
return made[-1]
88-
89-
monkeypatch.setattr(absurd_sdk.AsyncConnection, "connect", connect)
90-
client = absurd_sdk.AsyncAbsurd("postgresql://localhost/absurd")
91-
92-
async def run():
93-
await client._ensure_connected()
94-
await client.close()
95-
await client._ensure_connected()
96-
97-
asyncio.run(run())
98-
99-
assert made == [client._conn]
100-
assert client._conn.closed

0 commit comments

Comments
 (0)