Skip to content

Commit 5dbb251

Browse files
committed
server settings
1 parent e29fe52 commit 5dbb251

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

packages/service-library/src/servicelib/db_asyncpg_utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ async def create_async_engine_and_pg_database_ready(
2626
- waits until db data is migrated (i.e. ready to use)
2727
- returns engine
2828
"""
29+
server_settings = None
30+
if settings.POSTGRES_CLIENT_NAME:
31+
server_settings = {
32+
"application_name": settings.POSTGRES_CLIENT_NAME,
33+
}
34+
2935
engine: AsyncEngine = create_async_engine(
3036
settings.dsn_with_async_sqlalchemy,
3137
pool_size=settings.POSTGRES_MINSIZE,
3238
max_overflow=settings.POSTGRES_MAXSIZE - settings.POSTGRES_MINSIZE,
33-
connect_args={
34-
"server_settings": {"application_name": settings.POSTGRES_CLIENT_NAME}
35-
},
39+
connect_args={"server_settings": server_settings},
3640
pool_pre_ping=True, # https://docs.sqlalchemy.org/en/14/core/pooling.html#dealing-with-disconnects
3741
future=True, # this uses sqlalchemy 2.0 API, shall be removed when sqlalchemy 2.0 is released
3842
)

services/web/server/tests/unit/with_dbs/01/test_db.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
@pytest.fixture
3131
def mock_asyncpg_in_setup_db(mocker: MockFixture) -> MockType:
32+
3233
original_setup = setup_db
3334

3435
mock_setup_db = mocker.patch(

services/web/server/tests/unit/with_dbs/conftest.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from pydantic import ByteSize, parse_obj_as
4242
from pytest_mock import MockerFixture
4343
from pytest_simcore.helpers.dict_tools import ConfigDict
44+
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
4445
from pytest_simcore.helpers.typing_env import EnvVarsDict
4546
from pytest_simcore.helpers.webserver_login import NewUser, UserInfoDict
4647
from pytest_simcore.helpers.webserver_parametrizations import MockedStorageSubsystem
@@ -125,6 +126,7 @@ def app_cfg(default_app_cfg: ConfigDict, unused_tcp_port_factory) -> ConfigDict:
125126

126127
@pytest.fixture
127128
def app_environment(
129+
monkeypatch: pytest.MonkeyPatch,
128130
app_cfg: ConfigDict,
129131
monkeypatch_setenv_from_app_config: Callable[[ConfigDict], dict[str, str]],
130132
) -> EnvVarsDict:
@@ -140,7 +142,14 @@ def app_environment(app_environment: dict[str, str], monkeypatch: pytest.MonkeyP
140142
"""
141143
print("+ web_server:")
142144
cfg = deepcopy(app_cfg)
143-
return monkeypatch_setenv_from_app_config(cfg)
145+
envs = monkeypatch_setenv_from_app_config(cfg)
146+
147+
#
148+
# NOTE: this emulates hostname: "wb-{{.Node.Hostname}}-{{.Task.Slot}}" in docker-compose that
149+
# affects PostgresSettings.POSTGRES_CLIENT_NAME
150+
#
151+
extra = setenvs_from_dict(monkeypatch, {"HOSTNAME": "wb-test_host.0"})
152+
return envs | extra
144153

145154

146155
@pytest.fixture

0 commit comments

Comments
 (0)