Skip to content

Commit 5599ce5

Browse files
committed
Update failing relative paths.
1 parent 743fc7b commit 5599ce5

File tree

2 files changed

+60
-23
lines changed

2 files changed

+60
-23
lines changed

apps/bfd-pipeline/bfd-pipeline-idr/test_pipeline.py

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,81 @@
2323
# seems to have issues with podman https://github.com/testcontainers/testcontainers-python/issues/753
2424
testcontainers_config.ryuk_disabled = True
2525

26+
# Set longer timeout for CI environments where image pulls take longer
27+
os.environ.setdefault("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE", "/var/run/docker.sock")
28+
os.environ.setdefault("TESTCONTAINERS_RYUK_DISABLED", "true")
29+
2630

2731
def _run_migrator(postgres: PostgresContainer) -> None:
2832
# Python recommends using an absolute path when running an executable
2933
# to avoid any ambiguity
3034
mvn = shutil.which("mvn") or "mvn"
35+
test_dir = Path(__file__).parent
36+
migrator_dir = test_dir.parent.parent / "bfd-db-migrator-ng"
37+
print(f"[MIGRATOR] Running mvn from: {migrator_dir}")
38+
print(f"[MIGRATOR] Using mvn: {mvn}")
3139
try:
32-
subprocess.run(
40+
result = subprocess.run(
3341
f"{mvn} flyway:migrate "
3442
"-Dflyway.url="
3543
f"jdbc:postgresql://localhost:{postgres.get_exposed_port(5432)}/{postgres.dbname} "
3644
f"-Dflyway.user={postgres.username} "
3745
f"-Dflyway.password={postgres.password}",
38-
cwd="../../bfd-db-migrator-ng",
46+
cwd=str(migrator_dir),
3947
shell=True,
4048
capture_output=True,
4149
check=True,
50+
timeout=60,
4251
)
52+
print("[MIGRATOR] Migration completed successfully")
53+
if result.stdout:
54+
print(f"[MIGRATOR] stdout: {result.stdout.decode()}")
55+
except subprocess.TimeoutExpired:
56+
print("[MIGRATOR] Migration timed out after 60 seconds", file=sys.stderr)
57+
raise
4358
except subprocess.CalledProcessError as ex:
44-
print(ex.output)
59+
print(f"[MIGRATOR] Migration failed with exit code {ex.returncode}", file=sys.stderr)
60+
if ex.stdout:
61+
print(f"[MIGRATOR] stdout: {ex.stdout.decode()}", file=sys.stderr)
62+
if ex.stderr:
63+
print(f"[MIGRATOR] stderr: {ex.stderr.decode()}", file=sys.stderr)
4564
raise
4665

4766

4867
@pytest.fixture(scope="module")
4968
def setup_db() -> Generator[PostgresContainer]:
50-
with PostgresContainer("postgres:16", driver="") as postgres:
51-
with psycopg.connect(postgres.get_connection_url()) as conn:
52-
with Path("./mock-idr.sql").open() as f:
53-
conn.execute(f.read()) # type: ignore
54-
conn.commit()
55-
56-
_run_migrator(postgres)
57-
load_from_csv(conn, "./test_samples1") # type: ignore
58-
59-
info = conn.info
60-
os.environ["BFD_DB_ENDPOINT"] = info.host
61-
os.environ["BFD_DB_PORT"] = str(info.port)
62-
os.environ["BFD_DB_NAME"] = info.dbname
63-
os.environ["BFD_DB_USERNAME"] = info.user
64-
os.environ["BFD_DB_PASSWORD"] = info.password
65-
os.environ["PARALLELISM"] = "2"
66-
os.environ["IDR_BATCH_SIZE"] = "100000"
67-
os.environ["IDR_LOAD_BENES"] = "true"
68-
os.environ["IDR_LOAD_CLAIMS"] = "true"
69-
yield postgres
69+
test_dir = Path(__file__).parent
70+
print("\n[FIXTURE] Starting PostgreSQL container with postgres:16")
71+
try:
72+
with PostgresContainer("postgres:16", driver="") as postgres:
73+
print(f"[FIXTURE] Container started on {postgres.get_exposed_port(5432)}")
74+
with psycopg.connect(postgres.get_connection_url()) as conn:
75+
print("[FIXTURE] Connected to database")
76+
print("[FIXTURE] Loading mock-idr.sql")
77+
with (test_dir / "mock-idr.sql").open() as f:
78+
conn.execute(f.read()) # type: ignore
79+
conn.commit()
80+
81+
print("[FIXTURE] Running flyway migrator")
82+
_run_migrator(postgres)
83+
print("[FIXTURE] Loading test samples")
84+
load_from_csv(conn, str(test_dir / "test_samples1")) # type: ignore
85+
86+
info = conn.info
87+
os.environ["BFD_DB_ENDPOINT"] = info.host
88+
os.environ["BFD_DB_PORT"] = str(info.port)
89+
os.environ["BFD_DB_NAME"] = info.dbname
90+
os.environ["BFD_DB_USERNAME"] = info.user
91+
os.environ["BFD_DB_PASSWORD"] = info.password
92+
os.environ["PARALLELISM"] = "2"
93+
os.environ["IDR_BATCH_SIZE"] = "100000"
94+
os.environ["IDR_LOAD_BENES"] = "true"
95+
os.environ["IDR_LOAD_CLAIMS"] = "true"
96+
print("[FIXTURE] Database setup complete")
97+
yield postgres
98+
except Exception as e:
99+
print(f"[FIXTURE] Error during database setup: {e}", file=sys.stderr)
100+
raise
70101

71102

72103
def test_pipeline(setup_db: PostgresContainer) -> None:

apps/pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dev-dependencies = [
2727
"ruff==0.13.2",
2828
"pyright==1.1.406",
2929
"pytest==8.4.2",
30+
"pytest-timeout>=2.1.0",
3031
# bfd-pipeline-idr dev dependencies
3132
"testcontainers>=4.13.1",
3233
]
@@ -86,3 +87,8 @@ venv = ".venv"
8687
exclude = [".venv", "**/bfd-model-idr/**", "**/bfd-model-rif/**", "**/bfd-pipeline-idr/**", "**/locust_tests/**", "**/synthetic-load-converter/**"]
8788
reportMissingImports = false
8889
reportMissingTypeStubs = false
90+
91+
[tool.pytest.ini_options]
92+
timeout = 600
93+
testpaths = ["bfd-pipeline/bfd-pipeline-idr"]
94+

0 commit comments

Comments
 (0)