Skip to content

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

Closed
avirajsingh7 wants to merge 12 commits intomainfrom
fix/test_db_
Closed

Use Isolated Test Database for Reliable and Consistent Test Runs#230
avirajsingh7 wants to merge 12 commits intomainfrom
fix/test_db_

Conversation

@avirajsingh7
Copy link
Copy Markdown
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.

@codecov
Copy link
Copy Markdown

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 removed this from Kaapi-dev Jun 18, 2025
@avirajsingh7 avirajsingh7 linked an issue Jun 20, 2025 that may be closed by this pull request
- 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

ports:
- 5432:5432
options: --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5
options: >-
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@AkhileshNegi AkhileshNegi deleted the fix/test_db_ branch April 2, 2026 04:03
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