-
Notifications
You must be signed in to change notification settings - Fork 20
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
8 changed files
with
135 additions
and
20 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
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
from diracx.core.exceptions import InvalidQueryError | ||
from diracx.db.sql.dummy.db import DummyDB | ||
from diracx.db.sql.utils import SQLDBConnectionError | ||
|
||
# Each DB test class must defined a fixture looking like this one | ||
# It allows to get an instance of an in memory DB, | ||
|
@@ -67,3 +68,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(SQLDBConnectionError): | ||
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import pytest | ||
|
||
|
||
def test_openapi(test_client): | ||
r = test_client.get("/api/openapi.json") | ||
assert r.status_code == 200 | ||
|
@@ -15,3 +18,16 @@ def test_installation_metadata(test_client): | |
|
||
assert r.status_code == 200 | ||
assert r.json() | ||
|
||
|
||
@pytest.mark.xfail(reason="TODO") | ||
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 | ||
assert r.json() |