File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import asyncio
22
3+ import psycopg
4+ from psycopg import pq
5+
36import absurd_sdk
47
58
@@ -49,29 +52,22 @@ def test_async_absurd_falls_back_to_default_absurd_uri(monkeypatch):
4952 assert client ._owned_conn is True
5053
5154
52- class MockConnection :
53- broken = False
54-
55- async def close (self ):
56- pass
57-
58-
59- def test_async_absurd_reconnects_only_after_an_interrupted_connection (monkeypatch ):
55+ def test_async_absurd_reconnects_after_an_interrupted_connection (monkeypatch ):
6056 made = []
6157
6258 async def connect (dsn , autocommit = True ):
63- made .append (MockConnection ())
59+ # Connecting to a nonexistent socket fails immediately, producing a
60+ # real psycopg connection that is `broken`: status BAD without a
61+ # clean close(), the same state a dropped connection leaves behind.
62+ made .append (psycopg .AsyncConnection (pq .PGconn .connect (b"host=/nonexistent" )))
6463 return made [- 1 ]
6564
6665 monkeypatch .setattr (absurd_sdk .AsyncConnection , "connect" , connect )
6766 client = absurd_sdk .AsyncAbsurd ("postgresql://localhost/absurd" )
6867
6968 async def run ():
7069 await client ._ensure_connected ()
71- made [0 ].broken = True
72- await client ._ensure_connected () # interrupted: replaced
73- await client .close ()
74- await client ._ensure_connected () # closed cleanly: not resurrected
70+ await client ._ensure_connected ()
7571
7672 asyncio .run (run ())
7773
You can’t perform that action at this time.
0 commit comments