Skip to content

Commit fccd24f

Browse files
chesterchengiefiru
authored andcommitted
test: cover PostgreSQL connection timeout
Signed-off-by: chestercheng <hi@chester.ch>
1 parent 0edd386 commit fccd24f

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

‎tests/test_health.py‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,26 @@
44

55
import pytest
66

7-
from argus import config, health
7+
from argus import config, database, health
8+
9+
10+
def test_create_db_engine_rounds_postgresql_connect_timeout(monkeypatch):
11+
"""Configure PostgreSQL's integer timeout without opening a connection."""
12+
captured = {}
13+
14+
def fake_create_engine(database_url, **kwargs):
15+
captured["database_url"] = database_url
16+
captured.update(kwargs)
17+
return object()
18+
19+
monkeypatch.setattr(database, "create_engine", fake_create_engine)
20+
21+
database.create_db_engine("postgresql+psycopg://user:pass@db/argus", 1.2)
22+
23+
assert captured == {
24+
"database_url": "postgresql+psycopg://user:pass@db/argus",
25+
"connect_args": {"connect_timeout": 2},
26+
}
827

928

1029
def test_check_database_succeeds_with_sqlite_url(tmp_path, monkeypatch):

0 commit comments

Comments
 (0)