Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions NotificationService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@
builder.Host.UseWolverine(opts =>
{
var connectionString = builder.Configuration.GetConnectionString("messaging")!;
opts.UseAzureServiceBus(connectionString)
.AutoProvision();
var azureServiceBus = opts.UseAzureServiceBus(connectionString);

// AutoProvision creates topics/subscriptions at host startup. Test harnesses use a
// fake ASB connection string that would hang the connection attempt. Gate on a config
// flag so tests can disable provisioning while leaving the rest of the
// Development-gated code (EF migration, OpenAPI) intact. See OrderService/Program.cs
// for the full rationale.
if (builder.Configuration.GetValue("Wolverine:AutoProvision", defaultValue: true))
{
azureServiceBus.AutoProvision();
}

// Listen to events from other services
opts.ListenToAzureServiceBusSubscription("order-events/notify-orders-sub");
Expand Down
19 changes: 17 additions & 2 deletions OrderService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,23 @@
builder.Host.UseWolverine(opts =>
{
var connectionString = builder.Configuration.GetConnectionString("messaging")!;
opts.UseAzureServiceBus(connectionString)
.AutoProvision();
var azureServiceBus = opts.UseAzureServiceBus(connectionString);

// AutoProvision creates topics/subscriptions on the Service Bus namespace at host
// startup. That's a real network operation against the configured endpoint, and it
// happens even when Wolverine's external transports are otherwise stubbed —
// provisioning fires before DisableAllExternalWolverineTransports() from a test
// factory's ConfigureTestServices takes effect. Integration tests use a fake ASB
// connection string ("sb://fake.servicebus.windows.net/...") so AutoProvision hangs
// trying to resolve/connect, eventually timing out at the CI runner's job limit.
//
// Gate on a config flag (not environment) so tests can disable provisioning while
// leaving the rest of the Development-gated code (EF migration, OpenAPI, Scalar)
// intact. Defaults to true so dev/prod behavior is unchanged.
if (builder.Configuration.GetValue("Wolverine:AutoProvision", defaultValue: true))
{
azureServiceBus.AutoProvision();
}

// Publish outgoing events to their topics
opts.PublishMessage<OrderPlacedEvent>().ToAzureServiceBusTopic("order-events");
Expand Down
13 changes: 11 additions & 2 deletions PaymentService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@
builder.Host.UseWolverine(opts =>
{
var connectionString = builder.Configuration.GetConnectionString("messaging")!;
opts.UseAzureServiceBus(connectionString)
.AutoProvision();
var azureServiceBus = opts.UseAzureServiceBus(connectionString);

// AutoProvision creates topics/subscriptions at host startup. Test harnesses use a
// fake ASB connection string that would hang the connection attempt. Gate on a config
// flag so tests can disable provisioning while leaving the rest of the
// Development-gated code (EF migration, OpenAPI) intact. See OrderService/Program.cs
// for the full rationale.
if (builder.Configuration.GetValue("Wolverine:AutoProvision", defaultValue: true))
{
azureServiceBus.AutoProvision();
}

// Publish outgoing events to their topics
opts.PublishMessage<PaymentCompletedEvent>().ToAzureServiceBusTopic("payment-events");
Expand Down
13 changes: 11 additions & 2 deletions ShippingService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@
builder.Host.UseWolverine(opts =>
{
var connectionString = builder.Configuration.GetConnectionString("messaging")!;
opts.UseAzureServiceBus(connectionString)
.AutoProvision();
var azureServiceBus = opts.UseAzureServiceBus(connectionString);

// AutoProvision creates topics/subscriptions at host startup. Test harnesses use a
// fake ASB connection string that would hang the connection attempt. Gate on a config
// flag so tests can disable provisioning while leaving the rest of the
// Development-gated code (EF migration, OpenAPI) intact. See OrderService/Program.cs
// for the full rationale.
if (builder.Configuration.GetValue("Wolverine:AutoProvision", defaultValue: true))
{
azureServiceBus.AutoProvision();
}

// Publish outgoing events to their topics
opts.PublishMessage<ShipmentDispatchedEvent>().ToAzureServiceBusTopic("shipping-events");
Expand Down
17 changes: 16 additions & 1 deletion tests/OrderService.Tests.Integration/OrderApiFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,29 @@ public async Task InitializeAsync()

public override async ValueTask DisposeAsync()
{
await _sqlServer.DisposeAsync();
// Dispose the host BEFORE the SQL container. Wolverine's DurableReceiver
// background service polls the wolverine.* outbox tables on a heartbeat; if SQL
// Server is torn down while the receiver is still running, every heartbeat hits
// "connection refused" and the unhandled exceptions crash the test host AFTER
// all tests passed. base.DisposeAsync() runs the host's StopAsync, which lets
// Wolverine's background services exit gracefully before we yank the DB.
await base.DisposeAsync();
await _sqlServer.DisposeAsync();
}

protected override void ConfigureWebHost(IWebHostBuilder builder)
{
ArgumentNullException.ThrowIfNull(builder);

// Disable Wolverine's .AutoProvision() in Program.cs. AutoProvision tries to
// create topics/subscriptions on the configured Service Bus namespace at host
// startup; against our fake "sb://fake.servicebus.windows.net/..." connection
// string it hangs trying to resolve/connect, eventually killing the test job
// at the runner's job limit. DisableAllExternalWolverineTransports() below
// handles the message-routing path; this handles broker-provisioning, which
// runs *before* ConfigureTestServices fires.
builder.UseSetting("Wolverine:AutoProvision", "false");

// Real SQL Server for the order DB + Wolverine outbox tables.
builder.UseSetting("ConnectionStrings:orders-db", _sqlServer.GetConnectionString());

Expand Down
Loading