mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-16 07:19:13 +08:00
Keep SQLite URLs intact when naming per-worker test databases
urlparse drops the empty authority of sqlite:///galaxy.sqlite, so a GALAXY_TEST_DBURI pointing at a relative SQLite file became the invalid sqlite:/galaxy_gw1.sqlite under xdist. Rename the database through SQLAlchemy's URL instead.
This commit is contained in:
@@ -22,6 +22,7 @@ from urllib.parse import urlparse
|
||||
|
||||
from a2wsgi import WSGIMiddleware
|
||||
from fastapi import FastAPI
|
||||
from sqlalchemy.engine import make_url
|
||||
from starlette.routing import Mount
|
||||
|
||||
from galaxy.app import UniverseApplication as GalaxyUniverseApplication
|
||||
@@ -442,9 +443,9 @@ def database_conf(db_path, prefix="GALAXY", prefer_template_database=False):
|
||||
|
||||
|
||||
def _worker_database_connection(database_connection: str, worker_id: str) -> str:
|
||||
parsed = urlparse(database_connection)
|
||||
root, ext = os.path.splitext(parsed.path)
|
||||
return parsed._replace(path=f"{root}_{worker_id}{ext}").geturl()
|
||||
url = make_url(database_connection)
|
||||
root, ext = os.path.splitext(url.database or "")
|
||||
return url.set(database=f"{root}_{worker_id}{ext}").render_as_string(hide_password=False)
|
||||
|
||||
|
||||
def install_database_conf(db_path, default_merged=False):
|
||||
|
||||
@@ -7,6 +7,7 @@ from starlette.routing import Mount
|
||||
from galaxy.webapps.galaxy.fast_app import include_tus
|
||||
from galaxy_test.driver import driver_util
|
||||
from galaxy_test.driver.driver_util import (
|
||||
_worker_database_connection,
|
||||
attempt_port,
|
||||
attempt_ports,
|
||||
reserve_port,
|
||||
@@ -38,6 +39,21 @@ def test_reserved_port_cannot_be_reserved_twice():
|
||||
sock.close()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"database_connection,expected",
|
||||
[
|
||||
(
|
||||
"postgresql+psycopg://postgres:postgres@localhost:5432/galaxy?client_encoding=utf8",
|
||||
"postgresql+psycopg://postgres:postgres@localhost:5432/galaxy_gw1?client_encoding=utf8",
|
||||
),
|
||||
("sqlite:///galaxy.sqlite", "sqlite:///galaxy_gw1.sqlite"),
|
||||
("sqlite:////tmp/galaxy.sqlite", "sqlite:////tmp/galaxy_gw1.sqlite"),
|
||||
],
|
||||
)
|
||||
def test_worker_database_connection(database_connection, expected):
|
||||
assert _worker_database_connection(database_connection, "gw1") == expected
|
||||
|
||||
|
||||
def _gx_app(new_file_path: str) -> Mock:
|
||||
# Spell out every setting caching_fast_app_factory reads: an unset Mock attribute is
|
||||
# a truthy Mock, which sends the factory down the uncached path.
|
||||
|
||||
Reference in New Issue
Block a user