From: Denis Laxalde Date: Tue, 2 Nov 2021 12:40:27 +0000 (+0100) Subject: Declare types for dynamically populated lists in pool tests X-Git-Tag: 3.0.2~2^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a434c60ea4f889b2746e10605b097b445155cc0;p=thirdparty%2Fpsycopg.git Declare types for dynamically populated lists in pool tests --- diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index 416b9bde0..47a17a252 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -4,7 +4,7 @@ import weakref from time import sleep, time from threading import Thread, Event from collections import Counter -from typing import Any +from typing import Any, List, Tuple import pytest @@ -114,7 +114,7 @@ def test_concurrent_filling(dsn, monkeypatch, retries): for retry in retries: with retry: - times = [] + times: List[float] = [] t0 = time() with pool.ConnectionPool(dsn, min_size=5, num_workers=2) as p: @@ -301,7 +301,7 @@ def test_queue(dsn, retries): for retry in retries: with retry: - results = [] + results: List[Tuple[int, float, int]] = [] with pool.ConnectionPool(dsn, min_size=2) as p: p.wait() ts = [Thread(target=worker, args=(i,)) for i in range(6)] @@ -331,8 +331,8 @@ def test_queue_size(dsn): else: success.append(True) - errors = [] - success = [] + errors: List[Exception] = [] + success: List[bool] = [] with pool.ConnectionPool(dsn, min_size=1, max_waiting=3) as p: p.wait() @@ -374,8 +374,8 @@ def test_queue_timeout(dsn, retries): for retry in retries: with retry: - results = [] - errors = [] + results: List[Tuple[int, float, int]] = [] + errors: List[Tuple[int, float, Exception]] = [] with pool.ConnectionPool(dsn, min_size=2, timeout=0.1) as p: ts = [Thread(target=worker, args=(i,)) for i in range(4)] @@ -402,7 +402,7 @@ def test_dead_client(dsn): if timeout > 0.2: raise - results = [] + results: List[int] = [] with pool.ConnectionPool(dsn, min_size=2) as p: ts = [ @@ -438,8 +438,8 @@ def test_queue_timeout_override(dsn, retries): for retry in retries: with retry: - results = [] - errors = [] + results: List[Tuple[int, float, int]] = [] + errors: List[Tuple[int, float, Exception]] = [] with pool.ConnectionPool(dsn, min_size=2, timeout=0.1) as p: ts = [Thread(target=worker, args=(i,)) for i in range(4)] @@ -652,7 +652,7 @@ def test_closed_queue(dsn, retries): for retry in retries: with retry: p = pool.ConnectionPool(dsn, min_size=1) - success = [] + success: List[str] = [] t1 = Thread(target=w1) t2 = Thread(target=w2) @@ -683,7 +683,7 @@ def test_grow(dsn, monkeypatch, retries): dsn, min_size=2, max_size=4, num_workers=3 ) as p: p.wait(1.0) - results = [] + results: List[Tuple[int, float]] = [] ts = [Thread(target=worker, args=(i,)) for i in range(6)] for t in ts: @@ -703,7 +703,7 @@ def test_shrink(dsn, monkeypatch): from psycopg_pool.pool import ShrinkPool - results = [] + results: List[Tuple[int, int]] = [] def run_hacked(self, pool): n0 = pool._nconns @@ -843,7 +843,7 @@ def test_resize(dsn): with p.connection() as conn: conn.execute("select pg_sleep(%s)", [t]) - size = [] + size: List[int] = [] with pool.ConnectionPool(dsn, min_size=2, max_idle=0.2) as p: s = Thread(target=sampler) diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index 58abfd5dd..d2542d313 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -3,7 +3,7 @@ import asyncio import logging from time import time from collections import Counter -from typing import Any +from typing import Any, List, Tuple import pytest @@ -112,7 +112,7 @@ async def test_concurrent_filling(dsn, monkeypatch, retries): async for retry in retries: with retry: - times = [] + times: List[float] = [] t0 = time() async with pool.AsyncConnectionPool( @@ -312,7 +312,7 @@ async def test_queue(dsn, retries): async for retry in retries: with retry: - results = [] + results: List[Tuple[int, float, int]] = [] async with pool.AsyncConnectionPool(dsn, min_size=2) as p: await p.wait() ts = [create_task(worker(i)) for i in range(6)] @@ -339,8 +339,8 @@ async def test_queue_size(dsn): else: success.append(True) - errors = [] - success = [] + errors: List[Exception] = [] + success: List[bool] = [] async with pool.AsyncConnectionPool(dsn, min_size=1, max_waiting=3) as p: await p.wait() @@ -379,8 +379,8 @@ async def test_queue_timeout(dsn, retries): async for retry in retries: with retry: - results = [] - errors = [] + results: List[Tuple[int, float, int]] = [] + errors: List[Tuple[int, float, Exception]] = [] async with pool.AsyncConnectionPool( dsn, min_size=2, timeout=0.1 @@ -407,7 +407,7 @@ async def test_dead_client(dsn): raise async with pool.AsyncConnectionPool(dsn, min_size=2) as p: - results = [] + results: List[int] = [] ts = [ create_task(worker(i, timeout)) for i, timeout in enumerate([0.4, 0.4, 0.1, 0.4, 0.4]) @@ -440,8 +440,8 @@ async def test_queue_timeout_override(dsn, retries): async for retry in retries: with retry: - results = [] - errors = [] + results: List[Tuple[int, float, int]] = [] + errors: List[Tuple[int, float, Exception]] = [] async with pool.AsyncConnectionPool( dsn, min_size=2, timeout=0.1 @@ -645,7 +645,7 @@ async def test_closed_queue(dsn, retries): async for retry in retries: with retry: p = pool.AsyncConnectionPool(dsn, min_size=1) - success = [] + success: List[str] = [] t1 = create_task(w1()) await asyncio.sleep(0.1) @@ -674,7 +674,7 @@ async def test_grow(dsn, monkeypatch, retries): ) as p: await p.wait(1.0) ts = [] - results = [] + results: List[Tuple[int, float]] = [] ts = [create_task(worker(i)) for i in range(6)] await asyncio.gather(*ts) @@ -691,7 +691,7 @@ async def test_shrink(dsn, monkeypatch): from psycopg_pool.pool_async import ShrinkPool - results = [] + results: List[Tuple[int, int]] = [] async def run_hacked(self, pool): n0 = pool._nconns @@ -837,7 +837,7 @@ async def test_resize(dsn): async with p.connection() as conn: await conn.execute("select pg_sleep(%s)", [t]) - size = [] + size: List[int] = [] async with pool.AsyncConnectionPool(dsn, min_size=2, max_idle=0.2) as p: s = create_task(sampler())