Skip to content

Commit 2c85e3f

Browse files
committed
constant
1 parent f1aa9c9 commit 2c85e3f

File tree

6 files changed

+38
-87
lines changed

6 files changed

+38
-87
lines changed

packages/postgres-database/tests/conftest.py

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,7 @@ def sync_engine(postgres_service: str) -> Iterable[sqlalchemy.engine.Engine]:
8181

8282

8383
@pytest.fixture
84-
def make_engine(
85-
postgres_service: str,
86-
) -> Callable[[bool], Awaitable[Engine] | sqlalchemy.engine.Engine]:
87-
dsn = postgres_service
88-
89-
def _make(is_async=True) -> Awaitable[Engine] | sqlalchemy.engine.Engine:
90-
return aiopg.sa.create_engine(dsn) if is_async else sa.create_engine(dsn)
91-
92-
return _make
93-
94-
95-
@pytest.fixture
96-
def make_asyncpg_engine(postgres_service: str) -> Callable[[bool], AsyncEngine]:
84+
def _make_asyncpg_engine(postgres_service: str) -> Callable[[bool], AsyncEngine]:
9785
# NOTE: users is responsible of `await engine.dispose()`
9886
dsn = postgres_service.replace("postgresql://", "postgresql+asyncpg://")
9987
minsize = 1
@@ -178,13 +166,15 @@ def pg_sa_engine(
178166

179167
@pytest.fixture
180168
async def aiopg_engine(
181-
pg_sa_engine: sqlalchemy.engine.Engine, make_engine: Callable
169+
pg_sa_engine: sqlalchemy.engine.Engine,
170+
postgres_service: str,
182171
) -> AsyncIterator[Engine]:
183172
"""
184173
Return an aiopg.sa engine connected to a responsive and migrated pg database
185174
"""
186-
187-
aiopg_sa_engine = await make_engine(is_async=True)
175+
# first start sync
176+
assert pg_sa_engine.url.database
177+
assert postgres_service.endswith(pg_sa_engine.url.database)
188178

189179
warnings.warn(
190180
"The 'aiopg_engine' is deprecated since we are replacing `aiopg` library by `sqlalchemy.ext.asyncio`."
@@ -194,12 +184,8 @@ async def aiopg_engine(
194184
stacklevel=2,
195185
)
196186

197-
yield aiopg_sa_engine
198-
199-
# closes async-engine connections and terminates
200-
aiopg_sa_engine.close()
201-
await aiopg_sa_engine.wait_closed()
202-
aiopg_sa_engine.terminate()
187+
async with aiopg.sa.create_engine(dsn=postgres_service) as aiopg_sa_engine:
188+
yield aiopg_sa_engine
203189

204190

205191
@pytest.fixture
@@ -213,14 +199,14 @@ async def connection(aiopg_engine: Engine) -> AsyncIterator[SAConnection]:
213199
async def asyncpg_engine( # <-- WE SHOULD USE THIS ONE
214200
is_pdb_enabled: bool,
215201
pg_sa_engine: sqlalchemy.engine.Engine,
216-
make_asyncpg_engine: Callable[[bool], AsyncEngine],
202+
_make_asyncpg_engine: Callable[[bool], AsyncEngine],
217203
) -> AsyncIterator[AsyncEngine]:
218204

219205
assert (
220206
pg_sa_engine
221207
), "Ensures pg db up, responsive, init (w/ tables) and/or migrated"
222208

223-
_apg_engine = make_asyncpg_engine(is_pdb_enabled)
209+
_apg_engine = _make_asyncpg_engine(is_pdb_enabled)
224210

225211
yield _apg_engine
226212

@@ -233,9 +219,7 @@ async def asyncpg_engine( # <-- WE SHOULD USE THIS ONE
233219

234220

235221
@pytest.fixture
236-
def create_fake_group(
237-
make_engine: Callable[..., Awaitable[Engine] | sqlalchemy.engine.Engine]
238-
) -> Iterator[Callable]:
222+
def create_fake_group(sync_engine: sqlalchemy.engine.Engine) -> Iterator[Callable]:
239223
"""factory to create standard group"""
240224
created_ids = []
241225

@@ -254,16 +238,13 @@ async def _creator(conn: SAConnection, **overrides) -> RowProxy:
254238

255239
yield _creator
256240

257-
sync_engine = make_engine(is_async=False)
258241
assert isinstance(sync_engine, sqlalchemy.engine.Engine)
259242
with sync_engine.begin() as conn:
260243
conn.execute(sa.delete(groups).where(groups.c.gid.in_(created_ids)))
261244

262245

263246
@pytest.fixture
264-
def create_fake_user(
265-
make_engine: Callable[..., Awaitable[Engine] | sqlalchemy.engine.Engine]
266-
) -> Iterator[Callable]:
247+
def create_fake_user(sync_engine: sqlalchemy.engine.Engine) -> Iterator[Callable]:
267248
"""factory to create a user w/ or w/o a standard group"""
268249

269250
created_ids = []
@@ -294,7 +275,6 @@ async def _creator(conn, group: RowProxy | None = None, **overrides) -> RowProxy
294275

295276
yield _creator
296277

297-
sync_engine = make_engine(is_async=False)
298278
assert isinstance(sync_engine, sqlalchemy.engine.Engine)
299279
with sync_engine.begin() as conn:
300280
conn.execute(users.delete().where(users.c.id.in_(created_ids)))

packages/postgres-database/tests/test_models_groups.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
# pylint: disable=unused-variable
44
# pylint: disable=too-many-arguments
55

6-
from collections.abc import AsyncIterator, Awaitable, Callable
6+
from collections.abc import Callable
77

88
import aiopg.sa.exc
99
import pytest
10-
import sqlalchemy as sa
1110
from aiopg.sa.connection import SAConnection
12-
from aiopg.sa.engine import Engine
1311
from aiopg.sa.result import ResultProxy, RowProxy
1412
from psycopg2.errors import ForeignKeyViolation, RaiseException, UniqueViolation
15-
from pytest_simcore.helpers import postgres_tools
1613
from pytest_simcore.helpers.faker_factories import random_user
17-
from simcore_postgres_database.models.base import metadata
1814
from simcore_postgres_database.webserver_models import (
1915
GroupType,
2016
groups,
@@ -24,31 +20,6 @@
2420
from sqlalchemy import func, literal_column, select
2521

2622

27-
@pytest.fixture
28-
async def connection(
29-
make_engine: Callable[[bool], Awaitable[Engine] | sa.engine.base.Engine]
30-
) -> AsyncIterator[SAConnection]:
31-
# setup
32-
33-
sync_engine = make_engine(is_async=False)
34-
metadata.drop_all(sync_engine)
35-
metadata.create_all(sync_engine)
36-
37-
async_engine = await make_engine(is_async=True)
38-
async with async_engine.acquire() as conn:
39-
yield conn
40-
41-
# tear-down
42-
43-
try:
44-
postgres_tools.force_drop_all_tables(sync_engine)
45-
finally:
46-
sync_engine.dispose()
47-
48-
async_engine.close()
49-
await async_engine.wait_closed()
50-
51-
5223
async def test_user_group_uniqueness(
5324
connection: SAConnection,
5425
create_fake_group: Callable,

packages/postgres-database/tests/test_uniqueness_in_comp_tasks.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
# pylint:disable=no-value-for-parameter
2-
# pylint:disable=unused-variable
3-
# pylint:disable=unused-argument
4-
# pylint:disable=redefined-outer-name
1+
# pylint: disable=redefined-outer-name
2+
# pylint: disable=unused-argument
3+
# pylint: disable=unused-variable
4+
# pylint: disable=too-many-arguments
55

66
import json
7-
from collections.abc import Awaitable, Callable
7+
from collections.abc import AsyncIterator
88

99
import aiopg.sa.engine
1010
import aiopg.sa.exc
1111
import pytest
1212
import sqlalchemy as sa
13+
import sqlalchemy.engine
1314
from psycopg2.errors import UniqueViolation # pylint: disable=no-name-in-module
1415
from pytest_simcore.helpers import postgres_tools
1516
from pytest_simcore.helpers.faker_factories import fake_pipeline, fake_task_factory
@@ -21,30 +22,24 @@
2122

2223
@pytest.fixture
2324
async def engine(
24-
make_engine: Callable[[bool], Awaitable[aiopg.sa.engine.Engine] | sa.engine.Engine]
25-
):
26-
async_engine: aiopg.sa.engine.Engine = await make_engine(is_async=True)
27-
sync_engine: sa.engine.Engine = make_engine(is_async=False)
25+
sync_engine: sqlalchemy.engine.Engine,
26+
aiopg_engine: aiopg.sa.engine.Engine,
27+
) -> AsyncIterator[aiopg.sa.engine.Engine]:
28+
2829
metadata.drop_all(sync_engine)
2930
metadata.create_all(sync_engine)
3031

31-
async with async_engine.acquire() as conn:
32+
async with aiopg_engine.acquire() as conn:
3233
await conn.execute(
3334
comp_pipeline.insert().values(**fake_pipeline(project_id="PA"))
3435
)
3536
await conn.execute(
3637
comp_pipeline.insert().values(**fake_pipeline(project_id="PB"))
3738
)
3839

39-
yield async_engine
40-
41-
try:
42-
postgres_tools.force_drop_all_tables(sync_engine)
43-
finally:
44-
sync_engine.dispose()
40+
yield aiopg_engine
4541

46-
async_engine.close()
47-
await async_engine.wait_closed()
42+
postgres_tools.force_drop_all_tables(sync_engine)
4843

4944

5045
async def test_unique_project_node_pairs(engine):

packages/postgres-database/tests/test_utils_migration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# pylint: disable=unused-argument
44
# pylint: disable=unused-variable
55

6-
from collections.abc import Callable
76

87
import pytest
98
import simcore_postgres_database.cli
9+
import sqlalchemy.engine
1010
from alembic.script.revision import MultipleHeads
1111
from simcore_postgres_database.utils_migration import get_current_head
1212
from sqlalchemy import inspect
@@ -23,8 +23,8 @@ def test_migration_has_no_branches():
2323
)
2424

2525

26-
def test_migration_upgrade_downgrade(make_engine: Callable):
27-
sync_engine = make_engine(is_async=False)
26+
def test_migration_upgrade_downgrade(sync_engine: sqlalchemy.engine.Engine):
27+
2828
assert sync_engine
2929
assert simcore_postgres_database.cli.discover.callback
3030
assert simcore_postgres_database.cli.upgrade.callback

packages/service-library/src/servicelib/redis/_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
from asyncio import Task
55
from dataclasses import dataclass, field
6+
from typing import Final
67
from uuid import uuid4
78

89
import redis.asyncio as aioredis
@@ -23,6 +24,9 @@
2324

2425
_logger = logging.getLogger(__name__)
2526

27+
# SEE https://github.com/ITISFoundation/osparc-simcore/pull/7077
28+
HEALTHCHECK_TASK_TIMEOUT_S: Final[float] = 3.0
29+
2630

2731
@dataclass
2832
class RedisClientSDK:
@@ -84,7 +88,9 @@ async def shutdown(self) -> None:
8488
assert self._health_check_task_started_event # nosec
8589
# NOTE: wait for the health check task to have started once before we can cancel it
8690
await self._health_check_task_started_event.wait()
87-
await cancel_wait_task(self._health_check_task, max_delay=3)
91+
await cancel_wait_task(
92+
self._health_check_task, max_delay=HEALTHCHECK_TASK_TIMEOUT_S
93+
)
8894

8995
await self._client.aclose(close_connection_pool=True)
9096

services/web/server/src/simcore_service_webserver/log.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
"gunicorn.access",
1919
"openapi_spec_validator",
2020
"servicelib.aiohttp.monitoring",
21-
# TODO: this is temporary
22-
# "sqlalchemy.engine",
23-
# "sqlalchemy",
21+
"sqlalchemy.engine",
22+
"sqlalchemy",
2423
"socketio",
2524
)
2625

0 commit comments

Comments
 (0)