-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: re-run on failures for integration tests (#5104)
- Loading branch information
1 parent
f0fec6b
commit b5995e9
Showing
7 changed files
with
117 additions
and
61 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
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
65 changes: 45 additions & 20 deletions
65
tests/integration/db_migrations/test_up_and_down_migrations.py
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,38 +1,63 @@ | ||
import os | ||
from typing import Optional, Tuple | ||
|
||
import pytest | ||
from alembic import command | ||
from alembic.config import Config | ||
from phoenix.config import ENV_PHOENIX_SQL_DATABASE_SCHEMA | ||
from sqlalchemy import Engine, text | ||
from sqlalchemy import Engine, Row, text | ||
|
||
|
||
def test_up_and_down_migrations( | ||
_alembic_config: Config, | ||
_engine: Engine, | ||
_alembic_config: Config, | ||
) -> None: | ||
table = "alembic_version" | ||
if _engine.url.get_backend_name().startswith("postgresql"): | ||
schema = os.environ[ENV_PHOENIX_SQL_DATABASE_SCHEMA] | ||
assert schema | ||
table = f"{schema}.{table}" | ||
stmt = text(f"SELECT version_num FROM {table}") | ||
with _engine.connect() as conn: | ||
with pytest.raises(BaseException, match=table): | ||
conn.execute(stmt) | ||
_engine.dispose() | ||
with pytest.raises(BaseException, match="alembic_version"): | ||
_version_num(_engine) | ||
|
||
for _ in range(2): | ||
_up(_engine, _alembic_config, "cf03bd6bae1d") | ||
_down(_engine, _alembic_config, "base") | ||
_up(_engine, _alembic_config, "cf03bd6bae1d") | ||
|
||
for _ in range(2): | ||
_up(_engine, _alembic_config, "10460e46d750") | ||
_down(_engine, _alembic_config, "cf03bd6bae1d") | ||
_up(_engine, _alembic_config, "10460e46d750") | ||
|
||
for _ in range(2): | ||
_up(_engine, _alembic_config, "3be8647b87d8") | ||
_down(_engine, _alembic_config, "10460e46d750") | ||
_up(_engine, _alembic_config, "3be8647b87d8") | ||
|
||
for _ in range(2): | ||
_up(_engine, _alembic_config, "cd164e83824f") | ||
_down(_engine, _alembic_config, "3be8647b87d8") | ||
_up(_engine, _alembic_config, "cd164e83824f") | ||
|
||
|
||
def _up(_engine: Engine, _alembic_config: Config, revision: str) -> None: | ||
with _engine.connect() as conn: | ||
_alembic_config.attributes["connection"] = conn | ||
command.upgrade(_alembic_config, "head") | ||
_engine.dispose() | ||
with _engine.connect() as conn: | ||
version_num = conn.execute(stmt).first() | ||
assert version_num == ("cd164e83824f",) | ||
command.upgrade(_alembic_config, revision) | ||
_engine.dispose() | ||
assert _version_num(_engine) == (revision,) | ||
|
||
|
||
def _down(_engine: Engine, _alembic_config: Config, revision: str) -> None: | ||
with _engine.connect() as conn: | ||
_alembic_config.attributes["connection"] = conn | ||
command.downgrade(_alembic_config, "base") | ||
command.downgrade(_alembic_config, revision) | ||
_engine.dispose() | ||
assert _version_num(_engine) == (None if revision == "base" else (revision,)) | ||
|
||
|
||
def _version_num(_engine: Engine) -> Optional[Row[Tuple[str]]]: | ||
schema_prefix = "" | ||
if _engine.url.get_backend_name().startswith("postgresql"): | ||
assert (schema := os.environ[ENV_PHOENIX_SQL_DATABASE_SCHEMA]) | ||
schema_prefix = f"{schema}." | ||
table, column = "alembic_version", "version_num" | ||
stmt = text(f"SELECT {column} FROM {schema_prefix}{table}") | ||
with _engine.connect() as conn: | ||
assert conn.execute(stmt).first() is None | ||
_engine.dispose() | ||
return conn.execute(stmt).first() |
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