Skip to content

feat(tests): add optional PostgreSQL integration test target - #133

Open
tomkabel wants to merge 5 commits into
mainfrom
feat/postgres-test-target
Open

feat(tests): add optional PostgreSQL integration test target#133
tomkabel wants to merge 5 commits into
mainfrom
feat/postgres-test-target

Conversation

@tomkabel

Copy link
Copy Markdown
Owner

Summary

Adds an optional PostgreSQL integration test target alongside the existing per-worker SQLite setup, enabling tests against a real database engine before production deployment.

Changes

Test Configuration (tests/conftest.py)

  • Respects TEST_DATABASE_URL environment variable when set
  • Falls back to per-worker SQLite for parallel unit tests (existing behavior)
  • No functional change for existing test runs

Docker Compose (docker-compose.test.yml)

  • test-db — PostgreSQL 15 Alpine with health check and resource limits
  • test-redis — Redis 7 Alpine with health check and resource limits
  • Ports bound to 127.0.0.1 for loopback-only access
  • Resource limits: 512MB memory / 0.5 CPU for DB, 128MB / 0.25 CPU for Redis

Hatch Scripts (pyproject.toml)

  • Added postgres script: runs full suite against PostgreSQL via TEST_DATABASE_URL
  • Matrix expanded to include postgres alongside sqlite

Usage

# Start test services
docker-compose -f docker-compose.test.yml up -d

# Run integration tests against PostgreSQL
TEST_DATABASE_URL=postgresql+asyncpg://test_user:test_pass@localhost:5433/test_db \
  hatch run test:postgres

# Tear down
docker-compose -f docker-compose.test.yml down -v

Motivation

SQLite in-memory is fast but doesn't catch PostgreSQL-specific behavior (e.g., constraint ordering, SERIAL vs UUID, RETURNING clause differences). Running the full suite against PostgreSQL before merging catches these integration issues.

Testing

  • Existing SQLite tests pass (no regression)
  • PostgreSQL target validates correctly against docker-compose services

Labels

testing

- Adds user_id and optional email to access token payload
- Maintains sub claim for backward compatibility
- Binds request_id to structlog contextvars for correlation
- Replace reset_stuck_jobs with requeue_stuck_jobs in main loop
- Zombie sweeper now writes outbox entry atomically with status update
- Avoids dual-write problem when Redis is unavailable
- Decouples outbox sync interval from cleanup (default 30s)
- Support TEST_DATABASE_URL override for real PostgreSQL tests
- Add test-db and test-redis services to docker-compose.test.yml
- Add postgres hatch script for integration testing
- Keep per-worker SQLite as fast default
@tomkabel tomkabel added the testing Test infrastructure or additions label Apr 30, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in Vooglaadija Apr 30, 2026
@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@tomkabel has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 34 minutes and 36 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 85db35a4-6825-4d86-b1ff-878338ed8c21

📥 Commits

Reviewing files that changed from the base of the PR and between 10495dc and a888013.

📒 Files selected for processing (7)
  • docker-compose.test.yml
  • pyproject.toml
  • tests/conftest.py
  • tests/test_worker/test_graceful_shutdown.py
  • tests/test_worker/test_main.py
  • worker/main.py
  • worker/zombie_sweeper.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/postgres-test-target

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 34 minutes and 36 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
app/api/routes/auth.py 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Test infrastructure or additions

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant