Skip to content

Commit 6a09446

Browse files
test: reduce query size for v1 long test (#339)
1 parent f0cd6f0 commit 6a09446

File tree

8 files changed

+67
-29
lines changed

8 files changed

+67
-29
lines changed

src/firebolt/service/V1/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
from typing import Optional
1+
from typing import TYPE_CHECKING, Optional
22

33
from firebolt.client import ClientV1 as Client
4-
from firebolt.service.manager import ResourceManager
4+
5+
if TYPE_CHECKING:
6+
from firebolt.service.manager import ResourceManager
57

68

79
class BaseService:
8-
def __init__(self, resource_manager: ResourceManager):
10+
def __init__(self, resource_manager: "ResourceManager"):
911
self.resource_manager = resource_manager
1012

1113
@property

src/firebolt/service/V1/region.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
from typing import Dict, List
1+
from typing import TYPE_CHECKING, Dict, List
22

33
from firebolt.model.V1.region import Region, RegionKey
4-
from firebolt.service.manager import ResourceManager
54
from firebolt.service.V1.base import BaseService
65
from firebolt.utils.urls import REGIONS_URL
76
from firebolt.utils.util import cached_property
87

8+
if TYPE_CHECKING:
9+
from firebolt.service.manager import ResourceManager
10+
911

1012
class RegionService(BaseService):
11-
def __init__(self, resource_manager: ResourceManager):
13+
def __init__(self, resource_manager: "ResourceManager"):
1214
"""
1315
Service to manage AWS regions (us-east-1, etc)
1416

src/firebolt/service/manager.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414
)
1515
from firebolt.common import Settings
1616
from firebolt.db import connect
17+
from firebolt.service.V1.binding import BindingService
18+
from firebolt.service.V1.database import DatabaseService as DatabaseServiceV1
19+
from firebolt.service.V1.engine import EngineService as EngineServiceV1
1720
from firebolt.service.V1.provider import get_provider_id
21+
from firebolt.service.V1.region import RegionService
22+
from firebolt.service.V2.database import DatabaseService as DatabaseServiceV2
23+
from firebolt.service.V2.engine import EngineService as EngineServiceV2
24+
from firebolt.service.V2.instance_type import InstanceTypeService
1825
from firebolt.utils.util import fix_url_schema
1926

2027
DEFAULT_TIMEOUT_SECONDS: int = 60 * 2
@@ -127,34 +134,25 @@ def __init__(
127134

128135
def _init_services_v2(self) -> None:
129136
# avoid circular import
130-
from firebolt.service.V2.database import DatabaseService
131-
from firebolt.service.V2.engine import EngineService
132-
from firebolt.service.V2.instance_type import InstanceTypeService
133137

134138
# Cloud Platform Resources (AWS)
135139
self.instance_types = InstanceTypeService(resource_manager=self)
136140

137141
# Firebolt Resources
138-
self.databases = DatabaseService(resource_manager=self)
139-
self.engines = EngineService(resource_manager=self)
142+
self.databases = DatabaseServiceV2(resource_manager=self)
143+
self.engines = EngineServiceV2(resource_manager=self)
140144

141145
# Not applicable to V2
142146
self.provider_id = None
143147

144148
def _init_services_v1(self) -> None:
145-
# avoid circular import
146-
from firebolt.service.V1.binding import BindingService
147-
from firebolt.service.V1.database import DatabaseService
148-
from firebolt.service.V1.engine import EngineService
149-
from firebolt.service.V1.region import RegionService
150-
151149
# Cloud Platform Resources (AWS)
152150
self.regions = RegionService(resource_manager=self) # type: ignore
153151

154152
# Firebolt Resources
155153
self.bindings = BindingService(resource_manager=self) # type: ignore
156-
self.engines = EngineService(resource_manager=self) # type: ignore
157-
self.databases = DatabaseService(resource_manager=self) # type: ignore
154+
self.engines = EngineServiceV1(resource_manager=self) # type: ignore
155+
self.databases = DatabaseServiceV1(resource_manager=self) # type: ignore
158156

159157
self.provider_id = get_provider_id(client=self._client)
160158

tests/integration/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from logging import getLogger
22
from os import environ
3+
from time import time
4+
from typing import Optional
35

46
from pytest import fixture, mark
57

@@ -142,3 +144,20 @@ def engine_url() -> str:
142144
@fixture(scope="session")
143145
def stopped_engine_url() -> str:
144146
return must_env(STOPPED_ENGINE_URL_ENV)
147+
148+
149+
@fixture(scope="function")
150+
def minimal_time():
151+
limit: Optional[float] = None
152+
153+
def setter(value):
154+
nonlocal limit
155+
limit = value
156+
157+
start = time()
158+
yield setter
159+
end = time()
160+
if limit is not None:
161+
assert (
162+
end - start >= limit
163+
), f"Test took {end - start} seconds, less than {limit} seconds"

tests/integration/dbapi/async/V1/test_queries_async.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import date, datetime
22
from decimal import Decimal
3-
from typing import Any, List
3+
from typing import Any, Callable, List
44

55
from pytest import fixture, mark, raises
66

@@ -170,14 +170,19 @@ async def test_select(
170170

171171

172172
@mark.slow
173-
@mark.timeout(timeout=600)
173+
@mark.timeout(timeout=1000)
174174
async def test_long_query(
175175
connection: Connection,
176+
minimal_time: Callable[[float], None],
176177
) -> None:
177178
"""AWS ALB TCP timeout set to 350; make sure we handle the keepalive correctly."""
179+
180+
# Fail test if it takes less than 350 seconds
181+
minimal_time(350)
182+
178183
with connection.cursor() as c:
179184
await c.execute(
180-
"SELECT checksum(*) FROM GENERATE_SERIES(1, 200000000000)", # approx 6m runtime
185+
"SELECT checksum(*) FROM GENERATE_SERIES(1, 250000000000)", # approx 6m runtime
181186
)
182187
data = await c.fetchall()
183188
assert len(data) == 1, "Invalid data size returned by fetchall"

tests/integration/dbapi/async/V2/test_queries_async.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import date, datetime
22
from decimal import Decimal
33
from os import environ
4-
from typing import List
4+
from typing import Callable, List
55

66
from pytest import fixture, mark, raises
77

@@ -104,8 +104,12 @@ async def test_select(
104104
@mark.timeout(timeout=550)
105105
async def test_long_query(
106106
connection: Connection,
107+
minimal_time: Callable[[float], None],
107108
) -> None:
108109
"""AWS ALB TCP timeout set to 350; make sure we handle the keepalive correctly."""
110+
111+
minimal_time(350)
112+
109113
with connection.cursor() as c:
110114
await c.execute(
111115
"SELECT checksum(*) FROM GENERATE_SERIES(1, 200000000000)", # approx 6m runtime

tests/integration/dbapi/sync/V1/test_queries.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import date, datetime
22
from decimal import Decimal
33
from threading import Thread
4-
from typing import Any, List
4+
from typing import Any, Callable, List
55

66
from pytest import fixture, mark, raises
77

@@ -121,14 +121,18 @@ def test_select(
121121

122122

123123
@mark.slow
124-
@mark.timeout(timeout=600)
124+
@mark.timeout(timeout=1000)
125125
def test_long_query(
126-
connection: Connection,
126+
connection: Connection, minimal_time: Callable[[float], None]
127127
) -> None:
128128
"""AWS ALB TCP timeout set to 350, make sure we handle the keepalive correctly."""
129+
130+
# Fail test if it takes less than 350 seconds
131+
minimal_time(350)
132+
129133
with connection.cursor() as c:
130134
c.execute(
131-
"SELECT checksum(*) FROM GENERATE_SERIES(1, 200000000000)", # approx 6m runtime
135+
"SELECT checksum(*) FROM GENERATE_SERIES(1, 250000000000)", # approx 6m runtime
132136
)
133137
data = c.fetchall()
134138
assert len(data) == 1, "Invalid data size returned by fetchall"

tests/integration/dbapi/sync/V2/test_queries.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from decimal import Decimal
33
from os import environ
44
from threading import Thread
5-
from typing import Any, List
5+
from typing import Any, Callable, List
66

77
from pytest import fixture, mark, raises
88

@@ -110,8 +110,12 @@ def test_select(
110110
@mark.timeout(timeout=550)
111111
def test_long_query(
112112
connection: Connection,
113+
minimal_time: Callable[[float], None],
113114
) -> None:
114-
"""AWS ALB TCP timeout set to 350, make sure we handle the keepalive correctly."""
115+
"""AWS ALB TCP timeout set to 350; make sure we handle the keepalive correctly."""
116+
117+
minimal_time(350)
118+
115119
with connection.cursor() as c:
116120
c.execute(
117121
"SELECT checksum(*) FROM GENERATE_SERIES(1, 200000000000)", # approx 6m runtime

0 commit comments

Comments
 (0)