Skip to content

Use Isolated Test Database for Reliable and Consistent Test Runs #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

avirajsingh7
Copy link
Collaborator

Target issue : #204

This PR addresses the issue where local test cases were running against the shared development database, causing inconsistent results due to residual or missing data. The updated implementation ensures that test cases now run against a dedicated test database (POSTGRES_DB_TEST), providing a clean and repeatable environment for every test session.

Copy link

codecov bot commented Jun 15, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/app/core/config.py 85.71% 1 Missing ⚠️
backend/app/tests_pre_start.py 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@avirajsingh7 avirajsingh7 self-assigned this Jun 15, 2025
@avirajsingh7 avirajsingh7 added ready-for-review enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Jun 15, 2025
@avirajsingh7 avirajsingh7 linked an issue Jun 20, 2025 that may be closed by this pull request
@@ -17,6 +17,20 @@ services:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}
- POSTGRES_USER=${POSTGRES_USER?Variable not set}
- POSTGRES_DB=${POSTGRES_DB?Variable not set}
- POSTGRES_DB_TEST=${POSTGRES_DB_TEST?Variable not set}
# Wait for main DB to be ready, then create test DB if it doesn't exist
command: >
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avirajsingh7

I am not sure if this is needed when we start the containers. It would be good to handle this during the test run.

Copy link
Collaborator

@kurund kurund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also please resolve the conflicts.

with Session(engine) as session:
with Session(test_engine) as session:
# Drop all tables and recreate them
SQLModel.metadata.drop_all(test_engine)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe drop the database instead of the tables.

@@ -18,7 +18,11 @@ jobs:
POSTGRES_DB: ai_platform
ports:
- 5432:5432
options: --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5
options: >-
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avirajsingh7

Is this intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kurund was part of my previous commit where I was modifying this file.
Either way it is fine

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to revert then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working on hold
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Testcases Run
3 participants