]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Add pool context test
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 13 Feb 2021 22:51:02 +0000 (23:51 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 12 Mar 2021 04:07:25 +0000 (05:07 +0100)
tests/test_pool.py

index b327cc1ddd8d112fa8718ffa815c76aba069d0b4..66772a87172e7ad476a1bbb67ca0df28fd19c7b9 100644 (file)
@@ -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)