Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: reduce query size for v1 long test #339

Merged
merged 5 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from logging import getLogger
from os import environ
from time import time
from typing import Optional

from pytest import fixture, mark

Expand Down Expand Up @@ -142,3 +144,20 @@ def engine_url() -> str:
@fixture(scope="session")
def stopped_engine_url() -> str:
return must_env(STOPPED_ENGINE_URL_ENV)


@fixture(scope="function")
def minimal_time():
limit: Optional[float] = None

def setter(value):
nonlocal limit
limit = value

start = time()
yield setter
end = time()
if limit is not None:
assert (
end - start >= limit
), f"Test took {end - start} seconds, less than {limit} seconds"
11 changes: 8 additions & 3 deletions tests/integration/dbapi/async/V1/test_queries_async.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import date, datetime
from decimal import Decimal
from typing import Any, List
from typing import Any, Callable, List

from pytest import fixture, mark, raises

Expand Down Expand Up @@ -170,14 +170,19 @@ async def test_select(


@mark.slow
@mark.timeout(timeout=600)
@mark.timeout(timeout=1000)
async def test_long_query(
connection: Connection,
minimal_time: Callable[[float], None],
) -> None:
"""AWS ALB TCP timeout set to 350; make sure we handle the keepalive correctly."""

# Fail test if it takes less than 350 seconds
minimal_time(350)

with connection.cursor() as c:
await c.execute(
"SELECT checksum(*) FROM GENERATE_SERIES(1, 200000000000)", # approx 6m runtime
"SELECT checksum(*) FROM GENERATE_SERIES(1, 250000000000)", # approx 6m runtime
)
data = await c.fetchall()
assert len(data) == 1, "Invalid data size returned by fetchall"
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/dbapi/async/V2/test_queries_async.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import date, datetime
from decimal import Decimal
from os import environ
from typing import List
from typing import Callable, List

from pytest import fixture, mark, raises

Expand Down Expand Up @@ -104,8 +104,12 @@ async def test_select(
@mark.timeout(timeout=550)
async def test_long_query(
connection: Connection,
minimal_time: Callable[[float], None],
) -> None:
"""AWS ALB TCP timeout set to 350; make sure we handle the keepalive correctly."""

minimal_time(350)

with connection.cursor() as c:
await c.execute(
"SELECT checksum(*) FROM GENERATE_SERIES(1, 200000000000)", # approx 6m runtime
Expand Down
12 changes: 8 additions & 4 deletions tests/integration/dbapi/sync/V1/test_queries.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import date, datetime
from decimal import Decimal
from threading import Thread
from typing import Any, List
from typing import Any, Callable, List

from pytest import fixture, mark, raises

Expand Down Expand Up @@ -121,14 +121,18 @@ def test_select(


@mark.slow
@mark.timeout(timeout=600)
@mark.timeout(timeout=1000)
def test_long_query(
connection: Connection,
connection: Connection, minimal_time: Callable[[float], None]
) -> None:
"""AWS ALB TCP timeout set to 350, make sure we handle the keepalive correctly."""

# Fail test if it takes less than 350 seconds
minimal_time(350)

with connection.cursor() as c:
c.execute(
"SELECT checksum(*) FROM GENERATE_SERIES(1, 200000000000)", # approx 6m runtime
"SELECT checksum(*) FROM GENERATE_SERIES(1, 250000000000)", # approx 6m runtime
)
data = c.fetchall()
assert len(data) == 1, "Invalid data size returned by fetchall"
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/dbapi/sync/V2/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from decimal import Decimal
from os import environ
from threading import Thread
from typing import Any, List
from typing import Any, Callable, List

from pytest import fixture, mark, raises

Expand Down Expand Up @@ -110,8 +110,12 @@ def test_select(
@mark.timeout(timeout=550)
def test_long_query(
connection: Connection,
minimal_time: Callable[[float], None],
) -> None:
"""AWS ALB TCP timeout set to 350, make sure we handle the keepalive correctly."""
"""AWS ALB TCP timeout set to 350; make sure we handle the keepalive correctly."""

minimal_time(350)

with connection.cursor() as c:
c.execute(
"SELECT checksum(*) FROM GENERATE_SERIES(1, 200000000000)", # approx 6m runtime
Expand Down
Loading