From: Daniele Varrazzo Date: Sat, 13 Feb 2021 22:51:02 +0000 (+0100) Subject: Add pool context test X-Git-Tag: 3.0.dev0~87^2~74 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9cb7ce7710b107e42454ab918e38b0a893ca5a36;p=thirdparty%2Fpsycopg.git Add pool context test --- diff --git a/tests/test_pool.py b/tests/test_pool.py index b327cc1dd..66772a871 100644 --- a/tests/test_pool.py +++ b/tests/test_pool.py @@ -24,8 +24,8 @@ def test_minconn_maxconn(dsn): pool.ConnectionPool(dsn, minconn=4, maxconn=2, num_workers=0) -def test_pool(dsn): - p = pool.ConnectionPool(dsn, minconn=2, timeout_sec=1.0) +def test_its_really_a_pool(dsn): + p = pool.ConnectionPool(dsn, minconn=2) with p.connection() as conn: with conn.execute("select pg_backend_pid()") as cur: (pid1,) = cur.fetchone() @@ -38,6 +38,17 @@ def test_pool(dsn): assert conn.pgconn.backend_pid in (pid1, pid2) +def test_connection_not_lost(dsn): + p = pool.ConnectionPool(dsn, minconn=1) + with pytest.raises(ZeroDivisionError): + with p.connection() as conn: + pid = conn.pgconn.backend_pid + 1 / 0 + + with p.connection() as conn2: + assert conn2.pgconn.backend_pid == pid + + @pytest.mark.slow def test_queue(dsn): p = pool.ConnectionPool(dsn, minconn=2)