From a859828a11bf57f46b744687e62cfeb68b25842c Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 29 Jun 2021 00:40:10 +0100 Subject: [PATCH] Skip timing-based tests on GitHub Actions MacOS runners --- .github/workflows/tests.yml | 3 +++ tests/conftest.py | 5 +++++ tests/pool/test_pool.py | 13 +++++++++++++ tests/pool/test_pool_async.py | 13 +++++++++++++ tests/pool/test_sched.py | 2 ++ tests/pool/test_sched_async.py | 2 +- tests/test_concurrency.py | 3 ++- tests/test_concurrency_async.py | 3 ++- tests/test_connection.py | 1 + tests/test_connection_async.py | 1 + 10 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 892255820..cae4ff92e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -121,6 +121,9 @@ jobs: env: PSYCOPG_IMPL: c PSYCOPG_TEST_DSN: "host=127.0.0.1 user=runner dbname=postgres" + # MacOS on GitHub Actions seems particularly slow. + # Don't run timing-based tests as they regularly fail. + PYTEST_ADDOPTS: "-m 'not timing'" steps: - uses: actions/checkout@v2 diff --git a/tests/conftest.py b/tests/conftest.py index d83cd42df..e42f141ae 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,6 +23,11 @@ def pytest_configure(config): "markers", "subprocess: the test import psycopg after subprocess" ) + config.addinivalue_line( + "markers", + "timing: the test is timing based and can fail on cheese hardware", + ) + def pytest_addoption(parser): parser.addoption( diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index 427b99ebd..39da2d0b4 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -82,6 +82,7 @@ def test_connection_not_lost(dsn): @pytest.mark.slow +@pytest.mark.timing def test_concurrent_filling(dsn, monkeypatch, retries): delay_connection(monkeypatch, 0.1) @@ -106,6 +107,7 @@ def test_concurrent_filling(dsn, monkeypatch, retries): @pytest.mark.slow +@pytest.mark.timing def test_wait_ready(dsn, monkeypatch): delay_connection(monkeypatch, 0.1) with pytest.raises(pool.PoolTimeout): @@ -267,6 +269,7 @@ def test_reset_broken(dsn, caplog): @pytest.mark.slow +@pytest.mark.timing def test_queue(dsn, retries): def worker(n): t0 = time() @@ -329,6 +332,7 @@ def test_queue_size(dsn): @pytest.mark.slow +@pytest.mark.timing def test_queue_timeout(dsn, retries): def worker(n): t0 = time() @@ -361,6 +365,7 @@ def test_queue_timeout(dsn, retries): @pytest.mark.slow +@pytest.mark.timing def test_dead_client(dsn): def worker(i, timeout): try: @@ -386,6 +391,7 @@ def test_dead_client(dsn): @pytest.mark.slow +@pytest.mark.timing def test_queue_timeout_override(dsn, retries): def worker(n): t0 = time() @@ -628,6 +634,7 @@ def test_closed_queue(dsn): @pytest.mark.slow +@pytest.mark.timing def test_grow(dsn, monkeypatch, retries): delay_connection(monkeypatch, 0.1) @@ -657,6 +664,7 @@ def test_grow(dsn, monkeypatch, retries): @pytest.mark.slow +@pytest.mark.timing def test_shrink(dsn, monkeypatch): from psycopg.pool.pool import ShrinkPool @@ -725,6 +733,7 @@ def test_reconnect(proxy, caplog, monkeypatch): @pytest.mark.slow +@pytest.mark.timing def test_reconnect_failure(proxy): proxy.start() @@ -779,6 +788,7 @@ def test_uniform_use(dsn, retries): @pytest.mark.slow +@pytest.mark.timing def test_resize(dsn): def sampler(): sleep(0.05) # ensure sampling happens after shrink check @@ -826,6 +836,7 @@ def test_jitter(): @pytest.mark.slow +@pytest.mark.timing def test_max_lifetime(dsn): with pool.ConnectionPool(dsn, min_size=1, max_lifetime=0.2) as p: sleep(0.1) @@ -870,6 +881,7 @@ def test_async_pool_not_supported(dsn): @pytest.mark.slow +@pytest.mark.timing def test_stats_measures(dsn): def worker(n): with p.connection() as conn: @@ -910,6 +922,7 @@ def test_stats_measures(dsn): @pytest.mark.slow +@pytest.mark.timing def test_stats_usage(dsn): def worker(n): try: diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index b35f988c1..c3a6ce95d 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -92,6 +92,7 @@ async def test_connection_not_lost(dsn): @pytest.mark.slow +@pytest.mark.timing async def test_concurrent_filling(dsn, monkeypatch, retries): delay_connection(monkeypatch, 0.1) @@ -118,6 +119,7 @@ async def test_concurrent_filling(dsn, monkeypatch, retries): @pytest.mark.slow +@pytest.mark.timing async def test_wait_ready(dsn, monkeypatch): delay_connection(monkeypatch, 0.1) with pytest.raises(pool.PoolTimeout): @@ -289,6 +291,7 @@ async def test_reset_broken(dsn, caplog): @pytest.mark.slow +@pytest.mark.timing async def test_queue(dsn, retries): async def worker(n): t0 = time() @@ -349,6 +352,7 @@ async def test_queue_size(dsn): @pytest.mark.slow +@pytest.mark.timing async def test_queue_timeout(dsn, retries): async def worker(n): t0 = time() @@ -383,6 +387,7 @@ async def test_queue_timeout(dsn, retries): @pytest.mark.slow +@pytest.mark.timing async def test_dead_client(dsn): async def worker(i, timeout): try: @@ -407,6 +412,7 @@ async def test_dead_client(dsn): @pytest.mark.slow +@pytest.mark.timing async def test_queue_timeout_override(dsn, retries): async def worker(n): t0 = time() @@ -640,6 +646,7 @@ async def test_closed_queue(dsn): @pytest.mark.slow +@pytest.mark.timing async def test_grow(dsn, monkeypatch, retries): delay_connection(monkeypatch, 0.1) @@ -669,6 +676,7 @@ async def test_grow(dsn, monkeypatch, retries): @pytest.mark.slow +@pytest.mark.timing async def test_shrink(dsn, monkeypatch): from psycopg.pool.async_pool import ShrinkPool @@ -742,6 +750,7 @@ async def test_reconnect(proxy, caplog, monkeypatch): @pytest.mark.slow +@pytest.mark.timing async def test_reconnect_failure(proxy): proxy.start() @@ -796,6 +805,7 @@ async def test_uniform_use(dsn, retries): @pytest.mark.slow +@pytest.mark.timing async def test_resize(dsn): async def sampler(): await asyncio.sleep(0.05) # ensure sampling happens after shrink check @@ -844,6 +854,7 @@ def test_jitter(): @pytest.mark.slow +@pytest.mark.timing async def test_max_lifetime(dsn): async with pool.AsyncConnectionPool( dsn, min_size=1, max_lifetime=0.2 @@ -880,6 +891,7 @@ async def test_check(dsn, caplog): @pytest.mark.slow +@pytest.mark.timing async def test_stats_measures(dsn): async def worker(n): async with p.connection() as conn: @@ -918,6 +930,7 @@ async def test_stats_measures(dsn): @pytest.mark.slow +@pytest.mark.timing async def test_stats_usage(dsn): async def worker(n): try: diff --git a/tests/pool/test_sched.py b/tests/pool/test_sched.py index e2bb5e126..9e3e1043b 100644 --- a/tests/pool/test_sched.py +++ b/tests/pool/test_sched.py @@ -7,6 +7,8 @@ import pytest from psycopg.pool.sched import Scheduler +pytestmark = pytest.mark.timing + @pytest.mark.slow def test_sched(): diff --git a/tests/pool/test_sched_async.py b/tests/pool/test_sched_async.py index bc06fd960..0a5ff8f88 100644 --- a/tests/pool/test_sched_async.py +++ b/tests/pool/test_sched_async.py @@ -8,7 +8,7 @@ import pytest from psycopg.compat import create_task from psycopg.pool.sched import AsyncScheduler -pytestmark = pytest.mark.asyncio +pytestmark = [pytest.mark.asyncio, pytest.mark.timing] @pytest.mark.slow diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py index 308eaa727..28de5e583 100644 --- a/tests/test_concurrency.py +++ b/tests/test_concurrency.py @@ -104,6 +104,7 @@ t.join() @pytest.mark.slow +@pytest.mark.timing def test_notifies(conn, dsn): nconn = psycopg.connect(dsn, autocommit=True) npid = nconn.pgconn.backend_pid @@ -193,4 +194,4 @@ def test_identify_closure(conn, dsn): with pytest.raises(psycopg.OperationalError): conn.execute("select 1") t1 = time.time() - assert 0.3 < t1 - t0 < 0.5 + assert 0.3 < t1 - t0 < 0.6 diff --git a/tests/test_concurrency_async.py b/tests/test_concurrency_async.py index 023d0ab43..3fdab911e 100644 --- a/tests/test_concurrency_async.py +++ b/tests/test_concurrency_async.py @@ -57,6 +57,7 @@ async def test_concurrent_execution(dsn): @pytest.mark.slow +@pytest.mark.timing async def test_notifies(aconn, dsn): nconn = await psycopg.AsyncConnection.connect(dsn, autocommit=True) npid = nconn.pgconn.backend_pid @@ -151,4 +152,4 @@ async def test_identify_closure(aconn, dsn): with pytest.raises(psycopg.OperationalError): await aconn.execute("select 1") t1 = time.time() - assert 0.3 < t1 - t0 < 0.5 + assert 0.3 < t1 - t0 < 0.6 diff --git a/tests/test_connection.py b/tests/test_connection.py index afc2c1ecb..826dad434 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -38,6 +38,7 @@ def test_connect_bad(): @pytest.mark.slow +@pytest.mark.timing @pytest.mark.skipif(sys.platform == "win32", reason="connect() hangs on Win32") def test_connect_timeout(): s = socket.socket(socket.AF_INET) diff --git a/tests/test_connection_async.py b/tests/test_connection_async.py index 779925f4d..845844d67 100644 --- a/tests/test_connection_async.py +++ b/tests/test_connection_async.py @@ -39,6 +39,7 @@ async def test_connect_str_subclass(dsn): @pytest.mark.slow +@pytest.mark.timing async def test_connect_timeout(): s = socket.socket(socket.AF_INET) s.bind(("", 0)) -- 2.47.3