Skip to content

test+infra: fixture compartilhado de Postgres + docker-compose verificado - #11

Merged
thomasmoreira merged 1 commit into
mainfrom
chore/test-fixture-and-compose
Jun 8, 2026
Merged

thomasmoreira merged 1 commit into
mainfrom
chore/test-fixture-and-compose

Conversation

@thomasmoreira

@thomasmoreira thomasmoreira commented Jun 8, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Tests

    • Refactored integration tests to use a centralized PostgreSQL fixture for improved test execution efficiency and resource management.
  • Chores

    • Updated Docker Compose to map PostgreSQL service to port 5433 on the host to avoid conflicts with local PostgreSQL instances.

…-compose

Resolve os dois pontos em aberto após o roteiro.

(1) Fixture compartilhado dos testes de integração:
- PostgresFixture (ICollectionFixture): UM container de Postgres para toda a suíte;
  cada teste recebe um banco isolado via CreateDatabaseAsync() (CREATE DATABASE)
- As 9 classes de teste passam a usar o fixture (banco por teste) em vez de subir o
  próprio container; os testes que usam RabbitMQ mantêm seu container (poucos)
- Resultado: churn de containers despenca, sem o flake transitório de start; suíte
  ~40% mais rápida (~1m35s -> ~55s), 17/17 estável em 3 execuções

(2) docker-compose verificado ponta a ponta (corrige porta do host):
- porta do Postgres no host: 5432 -> 5433 (evita colisão com Postgres local;
  os serviços se falam por postgres:5432 na rede do compose de qualquer forma)
- `docker compose up` validado ao vivo: POST /orders -> Confirmed, estoque 100->98,
  payment Charged; e o caminho de compensação (valor > limite) -> Cancelled,
  estoque restaurado, payment Failed

Build limpo (0/0); unit 4/4; integration 17/17.
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a5e53a86-4c63-4bfc-badb-46e27664b3ec

📥 Commits

Reviewing files that changed from the base of the PR and between 0588cd7 and 9281db1.

📒 Files selected for processing (11)
  • docker/docker-compose.yml
  • tests/Integration/ChoreographyCoordinatorTests.cs
  • tests/Integration/EndToEndResilienceTests.cs
  • tests/Integration/InboxProcessorTests.cs
  • tests/Integration/InventoryReserveStockTests.cs
  • tests/Integration/OrderSagaOrchestrationTests.cs
  • tests/Integration/OutboxDispatcherTests.cs
  • tests/Integration/PaymentsChargeTests.cs
  • tests/Integration/PlaceOrderTests.cs
  • tests/Integration/PostgresFixture.cs
  • tests/Integration/RabbitMqConsumerHostTests.cs

📝 Walkthrough

Walkthrough

This pull request centralizes PostgreSQL lifecycle management for integration tests by introducing a shared PostgresFixture and refactoring 9 test classes to use it. The fixture creates isolated databases per test run via CreateDatabaseAsync(), reducing per-test container overhead. Docker Compose port mapping is updated to avoid clashes with local Postgres.

Changes

PostgreSQL Fixture and Test Infrastructure Adoption

Layer / File(s) Summary
PostgreSQL Fixture Infrastructure
tests/Integration/PostgresFixture.cs, docker/docker-compose.yml
Introduces PostgresFixture implementing IAsyncLifetime to manage a shared postgres:17-alpine container and create per-test databases via SQL. Adds IntegrationCollection xUnit collection definition for fixture binding. Updates Docker Compose PostgreSQL host port from 5432 to 5433 to prevent local Postgres conflicts.
Order and Choreography Test Migration
tests/Integration/ChoreographyCoordinatorTests.cs, tests/Integration/OrderSagaOrchestrationTests.cs, tests/Integration/PlaceOrderTests.cs
Refactors three order-related tests to inject PostgresFixture via primary constructors, use [Collection(IntegrationCollection.Name)] attribute, create isolated databases during InitializeAsync, and configure OrdersDbContext with fixture-provided connection strings instead of individual containers.
Messaging Infrastructure Test Migration
tests/Integration/OutboxDispatcherTests.cs, tests/Integration/InboxProcessorTests.cs
Refactors messaging tests to adopt shared fixture: removes Testcontainers.PostgreSql dependencies, accepts PostgresFixture via primary constructor, creates per-test databases, runs EF Core migrations, and wires TestDbContext and MessagingTestDbContext to use fixture connections.
Domain Services and Resilience Test Migration
tests/Integration/InventoryReserveStockTests.cs, tests/Integration/PaymentsChargeTests.cs, tests/Integration/RabbitMqConsumerHostTests.cs, tests/Integration/EndToEndResilienceTests.cs
Refactors four remaining tests (inventory, payments, consumer host, and end-to-end resilience) to use PostgresFixture, creating isolated databases and configuring InventoryDbContext, PaymentsDbContext, and multi-context verifiers with fixture-provided connections. Separates RabbitMQ lifecycle management from Postgres cleanup where applicable.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A shared Postgres home, now that's quite neat,
Nine tests find shelter where the fixtures meet!
No more containers born and torn—just one, so fleet,
With databases blooming per test run, complete. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title is in Portuguese and uses non-standard terminology ('compartilhado' instead of 'shared'); however, it does accurately describe the main changes: a shared Postgres fixture and docker-compose verification for testing infrastructure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/test-fixture-and-compose

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

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

@thomasmoreira
thomasmoreira merged commit 0003bf1 into main Jun 8, 2026
1 of 2 checks passed
@thomasmoreira
thomasmoreira deleted the chore/test-fixture-and-compose branch June 8, 2026 21:07
thomasmoreira added a commit that referenced this pull request Jun 10, 2026
…-compose (#11)

Resolve os dois pontos em aberto após o roteiro.

(1) Fixture compartilhado dos testes de integração:
- PostgresFixture (ICollectionFixture): UM container de Postgres para toda a suíte;
  cada teste recebe um banco isolado via CreateDatabaseAsync() (CREATE DATABASE)
- As 9 classes de teste passam a usar o fixture (banco por teste) em vez de subir o
  próprio container; os testes que usam RabbitMQ mantêm seu container (poucos)
- Resultado: churn de containers despenca, sem o flake transitório de start; suíte
  ~40% mais rápida (~1m35s -> ~55s), 17/17 estável em 3 execuções

(2) docker-compose verificado ponta a ponta (corrige porta do host):
- porta do Postgres no host: 5432 -> 5433 (evita colisão com Postgres local;
  os serviços se falam por postgres:5432 na rede do compose de qualquer forma)
- `docker compose up` validado ao vivo: POST /orders -> Confirmed, estoque 100->98,
  payment Charged; e o caminho de compensação (valor > limite) -> Cancelled,
  estoque restaurado, payment Failed

Build limpo (0/0); unit 4/4; integration 17/17.
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