Skip to content

fix(testing): harden CI DB initialization and ASGI lifespan setup for stable API tests#2

Merged
weijt606 merged 3 commits into
mainfrom
dev
Apr 5, 2026
Merged

fix(testing): harden CI DB initialization and ASGI lifespan setup for stable API tests#2
weijt606 merged 3 commits into
mainfrom
dev

Conversation

@weijt606
Copy link
Copy Markdown
Owner

@weijt606 weijt606 commented Apr 5, 2026

Summary

This PR stabilizes backend CI tests by fixing database/table initialization timing and ASGI test app startup behavior across the latest three commits.

Scope

  • Commit 1: 2efd67c
  • Commit 2: 63d64ce
  • Commit 3: f3bd135

Problem

CI intermittently failed on API tests with:

  • UndefinedTableError: relation "resources" does not exist
  • async runtime instability around test setup/startup ordering

The failures happened when tests queried DB-backed routes before schema creation or before app startup lifecycle was properly applied.

What Changed

  • Added session-level test stabilization for async DB usage and loop consistency.
  • Added explicit CI schema bootstrap (Base.metadata.create_all) before test execution in backend and integration jobs.
  • Updated ASGI test client fixture to run FastAPI lifespan context explicitly, ensuring startup/shutdown hooks run during tests.

Why This Fix Works

  • The resources table is now guaranteed to exist before API tests run.
  • Test environment startup order is deterministic.
  • API routes depending on startup-initialized resources no longer race CI timing.

Validation

  • Local CI-like backend run (not integration) passes:
    • 15 passed, 1 skipped, 1 deselected
  • Integration compare test path remains passing in CI-like env.
  • The previously reported UndefinedTableError path is covered by explicit schema bootstrap plus lifespan-managed test client setup.

Risk

  • Low risk.
  • Changes are isolated to test/CI setup and do not alter production runtime behavior.

Expected Outcome

  • Backend CI tests should no longer fail due to missing resources table or startup ordering issues.

@weijt606 weijt606 merged commit 79b719e into main Apr 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant