]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Rename pool.wait_ready() to pool.wait()
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 8 Mar 2021 02:32:34 +0000 (03:32 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 12 Mar 2021 04:07:25 +0000 (05:07 +0100)
psycopg3/psycopg3/pool/async_pool.py
psycopg3/psycopg3/pool/pool.py
tests/pool/test_pool.py
tests/pool/test_pool_async.py

index 592e5bc6314d40f316d96a14e984a279425c2d44..579f5ed31fd8ab33546bfa9b7887c19ab1b0f442 100644 (file)
@@ -108,7 +108,7 @@ class AsyncConnectionPool(BasePool[AsyncConnection]):
                     "task run %s failed: %s: %s", task, e.__class__.__name__, e
                 )
 
-    async def wait_ready(self, timeout: float = 30.0) -> None:
+    async def wait(self, timeout: float = 30.0) -> None:
         """
         Wait for the pool to be full after init.
 
@@ -129,6 +129,7 @@ class AsyncConnectionPool(BasePool[AsyncConnection]):
             )
 
         async with self._lock:
+            assert self._pool_full_event
             self._pool_full_event = None
 
     @asynccontextmanager
index 08a7435c486a5f0af7645733527236583843bd54..ece4a7c32805dcf741691cce0cf13e5dff790132 100644 (file)
@@ -89,7 +89,7 @@ class ConnectionPool(BasePool[Connection]):
         for i in range(len(self._workers)):
             self.run_task(StopWorker(self))
 
-    def wait_ready(self, timeout: float = 30.0) -> None:
+    def wait(self, timeout: float = 30.0) -> None:
         """
         Wait for the pool to be full after init.
 
@@ -108,6 +108,7 @@ class ConnectionPool(BasePool[Connection]):
             )
 
         with self._lock:
+            assert self._pool_full_event
             self._pool_full_event = None
 
     @contextmanager
index ea15d5cb3f4acff5c7067e368f652b1961fdcf1d..a1fe95301383d296af0e10048e314862d109aae5 100644 (file)
@@ -87,7 +87,7 @@ def test_concurrent_filling(dsn, monkeypatch, retries):
             t0 = time()
 
             with pool.ConnectionPool(dsn, minconn=5, num_workers=2) as p:
-                p.wait_ready(1.0)
+                p.wait(1.0)
                 want_times = [0.1, 0.1, 0.2, 0.2, 0.3]
                 assert len(times) == len(want_times)
                 for got, want in zip(times, want_times):
@@ -99,14 +99,14 @@ def test_wait_ready(dsn, monkeypatch):
     delay_connection(monkeypatch, 0.1)
     with pytest.raises(pool.PoolTimeout):
         with pool.ConnectionPool(dsn, minconn=4, num_workers=1) as p:
-            p.wait_ready(0.3)
+            p.wait(0.3)
 
     with pool.ConnectionPool(dsn, minconn=4, num_workers=1) as p:
-        p.wait_ready(0.5)
+        p.wait(0.5)
 
     with pool.ConnectionPool(dsn, minconn=4, num_workers=2) as p:
-        p.wait_ready(0.3)
-        p.wait_ready(0.0001)  # idempotent
+        p.wait(0.3)
+        p.wait(0.0001)  # idempotent
 
 
 @pytest.mark.slow
@@ -115,7 +115,7 @@ def test_setup_no_timeout(dsn, proxy):
         with pool.ConnectionPool(
             proxy.client_dsn, minconn=1, num_workers=1
         ) as p:
-            p.wait_ready(0.2)
+            p.wait(0.2)
 
     with pool.ConnectionPool(proxy.client_dsn, minconn=1, num_workers=1) as p:
         sleep(0.5)
@@ -161,7 +161,7 @@ def test_configure_broken(dsn, caplog):
 
     with pool.ConnectionPool(minconn=1, configure=configure) as p:
         with pytest.raises(pool.PoolTimeout):
-            p.wait_ready(timeout=0.5)
+            p.wait(timeout=0.5)
 
     assert caplog.records
     assert "WAT" in caplog.records[0].message
@@ -417,7 +417,7 @@ def test_del_no_warning(dsn, recwarn):
     with p.connection() as conn:
         conn.execute("select 1")
 
-    p.wait_ready()
+    p.wait()
     ref = weakref.ref(p)
     del p
     assert not ref()
@@ -505,7 +505,7 @@ def test_grow(dsn, monkeypatch, retries):
             with pool.ConnectionPool(
                 dsn, minconn=2, maxconn=4, num_workers=3
             ) as p:
-                p.wait_ready(1.0)
+                p.wait(1.0)
                 results = []
 
                 ts = [Thread(target=worker, args=(i,)) for i in range(6)]
@@ -539,7 +539,7 @@ def test_shrink(dsn, monkeypatch):
             conn.execute("select pg_sleep(0.1)")
 
     with pool.ConnectionPool(dsn, minconn=2, maxconn=4, max_idle=0.2) as p:
-        p.wait_ready(5.0)
+        p.wait(5.0)
         assert p.max_idle == 0.2
 
         ts = [Thread(target=worker, args=(i,)) for i in range(4)]
@@ -561,7 +561,7 @@ def test_reconnect(proxy, caplog, monkeypatch):
 
     proxy.start()
     with pool.ConnectionPool(proxy.client_dsn, minconn=1) as p:
-        p.wait_ready(2.0)
+        p.wait(2.0)
         proxy.stop()
 
         with pytest.raises(psycopg3.OperationalError):
@@ -570,7 +570,7 @@ def test_reconnect(proxy, caplog, monkeypatch):
 
         sleep(1.0)
         proxy.start()
-        p.wait_ready()
+        p.wait()
 
         with p.connection() as conn:
             conn.execute("select 1")
@@ -604,7 +604,7 @@ def test_reconnect_failure(proxy):
         reconnect_timeout=1.0,
         reconnect_failed=failed,
     ) as p:
-        p.wait_ready(2.0)
+        p.wait(2.0)
         proxy.stop()
 
         with pytest.raises(psycopg3.OperationalError):
@@ -701,11 +701,11 @@ def test_max_lifetime(dsn):
 def test_check(dsn, caplog):
     caplog.set_level(logging.WARNING, logger="psycopg3.pool")
     with pool.ConnectionPool(dsn, minconn=4) as p:
-        p.wait_ready(1.0)
+        p.wait(1.0)
         with p.connection() as conn:
             pid = conn.pgconn.backend_pid
 
-        p.wait_ready(1.0)
+        p.wait(1.0)
         pids = set(conn.pgconn.backend_pid for conn in p._pool)
         assert pid in pids
         conn.close()
@@ -713,7 +713,7 @@ def test_check(dsn, caplog):
         assert len(caplog.records) == 0
         p.check()
         assert len(caplog.records) == 1
-        p.wait_ready(1.0)
+        p.wait(1.0)
         pids2 = set(conn.pgconn.backend_pid for conn in p._pool)
         assert len(pids & pids2) == 3
         assert pid not in pids2
index 123fb12a4f8810bc3eb8183e10f8e7f3332d5a70..501f99da29e80a52d881cf47add9dd3273e7890d 100644 (file)
@@ -99,7 +99,7 @@ async def test_concurrent_filling(dsn, monkeypatch, retries):
             async with pool.AsyncConnectionPool(
                 dsn, minconn=5, num_workers=2
             ) as p:
-                await p.wait_ready(1.0)
+                await p.wait(1.0)
                 want_times = [0.1, 0.1, 0.2, 0.2, 0.3]
                 assert len(times) == len(want_times)
                 for got, want in zip(times, want_times):
@@ -113,14 +113,14 @@ async def test_wait_ready(dsn, monkeypatch):
         async with pool.AsyncConnectionPool(
             dsn, minconn=4, num_workers=1
         ) as p:
-            await p.wait_ready(0.3)
+            await p.wait(0.3)
 
     async with pool.AsyncConnectionPool(dsn, minconn=4, num_workers=1) as p:
-        await p.wait_ready(0.5)
+        await p.wait(0.5)
 
     async with pool.AsyncConnectionPool(dsn, minconn=4, num_workers=2) as p:
-        await p.wait_ready(0.3)
-        await p.wait_ready(0.0001)  # idempotent
+        await p.wait(0.3)
+        await p.wait(0.0001)  # idempotent
 
 
 @pytest.mark.slow
@@ -129,7 +129,7 @@ async def test_setup_no_timeout(dsn, proxy):
         async with pool.AsyncConnectionPool(
             proxy.client_dsn, minconn=1, num_workers=1
         ) as p:
-            await p.wait_ready(0.2)
+            await p.wait(0.2)
 
     async with pool.AsyncConnectionPool(
         proxy.client_dsn, minconn=1, num_workers=1
@@ -177,7 +177,7 @@ async def test_configure_broken(dsn, caplog):
 
     async with pool.AsyncConnectionPool(minconn=1, configure=configure) as p:
         with pytest.raises(pool.PoolTimeout):
-            await p.wait_ready(timeout=0.5)
+            await p.wait(timeout=0.5)
 
     assert caplog.records
     assert "WAT" in caplog.records[0].message
@@ -509,7 +509,7 @@ async def test_grow(dsn, monkeypatch, retries):
             async with pool.AsyncConnectionPool(
                 dsn, minconn=2, maxconn=4, num_workers=3
             ) as p:
-                await p.wait_ready(1.0)
+                await p.wait(1.0)
                 ts = []
                 results = []
 
@@ -545,7 +545,7 @@ async def test_shrink(dsn, monkeypatch):
     async with pool.AsyncConnectionPool(
         dsn, minconn=2, maxconn=4, max_idle=0.2
     ) as p:
-        await p.wait_ready(5.0)
+        await p.wait(5.0)
         assert p.max_idle == 0.2
 
         ts = [create_task(worker(i)) for i in range(4)]
@@ -565,7 +565,7 @@ async def test_reconnect(proxy, caplog, monkeypatch):
 
     proxy.start()
     async with pool.AsyncConnectionPool(proxy.client_dsn, minconn=1) as p:
-        await p.wait_ready(2.0)
+        await p.wait(2.0)
         proxy.stop()
 
         with pytest.raises(psycopg3.OperationalError):
@@ -574,7 +574,7 @@ async def test_reconnect(proxy, caplog, monkeypatch):
 
         await asyncio.sleep(1.0)
         proxy.start()
-        await p.wait_ready()
+        await p.wait()
 
         async with p.connection() as conn:
             await conn.execute("select 1")
@@ -613,7 +613,7 @@ async def test_reconnect_failure(proxy):
         reconnect_timeout=1.0,
         reconnect_failed=failed,
     ) as p:
-        await p.wait_ready(2.0)
+        await p.wait(2.0)
         proxy.stop()
 
         with pytest.raises(psycopg3.OperationalError):
@@ -711,11 +711,11 @@ async def test_max_lifetime(dsn):
 async def test_check(dsn, caplog):
     caplog.set_level(logging.WARNING, logger="psycopg3.pool")
     async with pool.AsyncConnectionPool(dsn, minconn=4) as p:
-        await p.wait_ready(1.0)
+        await p.wait(1.0)
         async with p.connection() as conn:
             pid = conn.pgconn.backend_pid
 
-        await p.wait_ready(1.0)
+        await p.wait(1.0)
         pids = set(conn.pgconn.backend_pid for conn in p._pool)
         assert pid in pids
         await conn.close()
@@ -723,7 +723,7 @@ async def test_check(dsn, caplog):
         assert len(caplog.records) == 0
         await p.check()
         assert len(caplog.records) == 1
-        await p.wait_ready(1.0)
+        await p.wait(1.0)
         pids2 = set(conn.pgconn.backend_pid for conn in p._pool)
         assert len(pids & pids2) == 3
         assert pid not in pids2