-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return a ServiceUnavailable Error when an SQL db is not reachable, and
retry connecting
- Loading branch information
Showing
7 changed files
with
123 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ dependencies: | |
- aiohttp | ||
- aiomysql | ||
- aiosqlite | ||
- asyncache | ||
- azure-core | ||
- cachetools | ||
######## | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ install_requires = | |
aiohttp | ||
aiomysql | ||
aiosqlite | ||
asyncache | ||
azure-core | ||
cachetools | ||
m2crypto >=0.38.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
import pytest | ||
|
||
from diracx.core.exceptions import InvalidQueryError | ||
from diracx.core.exceptions import DBConnectionError, InvalidQueryError | ||
from diracx.db.sql.dummy.db import DummyDB | ||
|
||
# Each DB test class must defined a fixture looking like this one | ||
|
@@ -67,3 +67,11 @@ async def test_insert_and_summary(dummy_db: DummyDB): | |
} | ||
], | ||
) | ||
|
||
|
||
async def test_bad_connection(): | ||
dummy_db = DummyDB("mysql+aiomysql://tata:[email protected]:3306/name") | ||
async with dummy_db.engine_context(): | ||
with pytest.raises(DBConnectionError): | ||
async with dummy_db: | ||
dummy_db.ping() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,15 @@ def test_installation_metadata(test_client): | |
|
||
assert r.status_code == 200 | ||
assert r.json() | ||
|
||
|
||
def test_unavailable_db(monkeypatch, test_client): | ||
# TODO | ||
# That does not work because test_client is already initialized | ||
monkeypatch.setenv( | ||
"DIRACX_DB_URL_JOBDB", "mysql+aiomysql://tata:[email protected]:3306/name" | ||
) | ||
|
||
r = test_client.get("/api/job/123") | ||
assert r.status_code == 503 | ||
Check failure on line 28 in tests/routers/test_generic.py GitHub Actions / pytest
|
||
assert r.json() |