Skip to content
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

Punchlist items for Wolverine 3.0 #1067

Merged
merged 4 commits into from
Oct 11, 2024
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
2 changes: 1 addition & 1 deletion docs/guide/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,6 @@ public static void using_preview_subscriptions(IMessageBus bus)
}
}
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/Runtime/Routing/routing_precedence.cs#L70-L84' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_preview_subscriptions' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/Runtime/Routing/routing_precedence.cs#L71-L85' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_preview_subscriptions' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

2 changes: 1 addition & 1 deletion docs/guide/durability/marten/distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ opts.Services.AddMarten(m =>
m.UseWolverineManagedEventSubscriptionDistribution = true;
});
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/MartenTests/Distribution/Support/SingleTenantContext.cs#L67-L87' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_opt_into_wolverine_managed_subscription_distribution' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/MartenTests/Distribution/Support/SingleTenantContext.cs#L70-L90' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_opt_into_wolverine_managed_subscription_distribution' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

::: tip
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/durability/marten/event-forwarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public async Task execution_of_forwarded_events_can_be_awaited_from_tests()
events[1].Data.ShouldBeOfType<FourthEvent>();
}
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/MartenTests/event_streaming.cs#L140-L169' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_execution_of_forwarded_events_can_be_awaited_from_tests' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/MartenTests/event_streaming.cs#L141-L170' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_execution_of_forwarded_events_can_be_awaited_from_tests' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Where the result contains `FourthEvent` because `SecondEvent` was forwarded as `SecondMessage` and that persisted `FourthEvent` in a handler such as:
Expand All @@ -178,5 +178,5 @@ public static Task HandleAsync(SecondMessage message, IDocumentSession session)
return session.SaveChangesAsync();
}
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/MartenTests/event_streaming.cs#L217-L223' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_execution_of_forwarded_events_second_message_to_fourth_event' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/MartenTests/event_streaming.cs#L218-L224' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_execution_of_forwarded_events_second_message_to_fourth_event' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
4 changes: 2 additions & 2 deletions docs/guide/durability/sqlserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ that they are utilizing the transactional inbox and outbox. The Sql Server queue
```cs
opts.ListenToSqlServerQueue("sender").BufferedInMemory();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/SqlServerTests/Transport/compliance_tests.cs#L62-L66' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_setting_sql_server_queue_to_buffered' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/SqlServerTests/Transport/compliance_tests.cs#L61-L65' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_setting_sql_server_queue_to_buffered' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Using this option just means that the Sql Server queues can be used for both sending or receiving with no integration
Expand Down Expand Up @@ -142,7 +142,7 @@ _listener = await Host.CreateDefaultBuilder()
.IncludeType<FooBarHandler>();
}).StartAsync();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/SqlServerTests/Transport/with_multiple_hosts.cs#L22-L58' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_sql_server_as_queue_between_two_apps' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/SqlServerTests/Transport/with_multiple_hosts.cs#L21-L57' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_sql_server_as_queue_between_two_apps' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

## Lightweight Saga Usage <Badge type="tip" text="3.0" />
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/handlers/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ theReceiver = await Host.CreateDefaultBuilder()
});
}).StartAsync();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/ErrorHandling/custom_error_action_raises_new_message.cs#L30-L48' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_inline_exception_handling_action' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/ErrorHandling/custom_error_action_raises_new_message.cs#L31-L49' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_inline_exception_handling_action' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Optionally, you can implement a new type to handle this same custom logic by
Expand All @@ -345,7 +345,7 @@ public class ShippingOrderFailurePolicy : UserDefinedContinuation
}
}
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/ErrorHandling/custom_error_action_raises_new_message.cs#L74-L94' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_shippingorderfailurepolicy' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/ErrorHandling/custom_error_action_raises_new_message.cs#L75-L95' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_shippingorderfailurepolicy' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

and register that secondary action like this:
Expand All @@ -363,7 +363,7 @@ theReceiver = await Host.CreateDefaultBuilder()
.Discard().And<ShippingOrderFailurePolicy>();
}).StartAsync();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/ErrorHandling/custom_error_action_raises_new_message.cs#L114-L126' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_registering_custom_user_continuation_policy' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/ErrorHandling/custom_error_action_raises_new_message.cs#L115-L127' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_registering_custom_user_continuation_policy' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
8 changes: 4 additions & 4 deletions docs/guide/handlers/sticky.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ message as an input.
```cs
public class StickyMessage;
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/Acceptance/sticky_message_handlers.cs#L172-L176' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_stickymessage' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/Acceptance/sticky_message_handlers.cs#L216-L220' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_stickymessage' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

And we're going to handle that `StickyMessage` message separately with two different handler types:
Expand All @@ -51,7 +51,7 @@ public static class GreenStickyHandler
}
}
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/Acceptance/sticky_message_handlers.cs#L178-L198' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_sticky_handler_attribute' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/Acceptance/sticky_message_handlers.cs#L222-L242' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_sticky_handler_attribute' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

::: tip
Expand Down Expand Up @@ -79,7 +79,7 @@ using var host = await Host.CreateDefaultBuilder()
opts.ListenAtPort(4000).Named("blue");
}).StartAsync();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/Acceptance/sticky_message_handlers.cs#L110-L120' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_named_listener_endpoint' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/Acceptance/sticky_message_handlers.cs#L154-L164' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_named_listener_endpoint' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

With all of that being said, the end result of the two `StickyMessage` handlers that are marked with `[StickyHandler]`
Expand Down Expand Up @@ -119,7 +119,7 @@ using var host = await Host.CreateDefaultBuilder()

}).StartAsync();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/Acceptance/sticky_message_handlers.cs#L125-L143' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_sticky_handlers_by_endpoint_with_fluent_interface' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/Acceptance/sticky_message_handlers.cs#L169-L187' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_sticky_handlers_by_endpoint_with_fluent_interface' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


2 changes: 1 addition & 1 deletion docs/guide/messaging/listeners.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ var host = await Host.CreateDefaultBuilder().UseWolverine(opts =>
.ListenWithStrictOrdering();
}).StartAsync();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/exclusive_listeners.cs#L33-L47' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_utilizing_listenwithstrictordering' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/exclusive_listeners.cs#L34-L48' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_utilizing_listenwithstrictordering' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

This option does a couple things:
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/messaging/transports/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ _receiver = await Host.CreateDefaultBuilder()
opts.ListenToMqttTopic("incoming/#").RetainMessages();
}).StartAsync();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Transports/MQTT/Wolverine.MQTT.Tests/listen_with_topic_wildcards.cs#L40-L49' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_listen_to_mqtt_topic_filter' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Transports/MQTT/Wolverine.MQTT.Tests/listen_with_topic_wildcards.cs#L41-L50' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_listen_to_mqtt_topic_filter' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

In the case of receiving any message that matches the topic filter *according to the [MQTT topic filter rules](https://cedalo.com/blog/mqtt-topics-and-mqtt-wildcards-explained/)*, that message
Expand Down Expand Up @@ -358,7 +358,7 @@ public static ClearMqttTopic Handle(TriggerZero message)
return new ClearMqttTopic("red");
}
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Transports/MQTT/Wolverine.MQTT.Tests/ack_smoke_tests.cs#L83-L97' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_ack_mqtt_topic' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Transports/MQTT/Wolverine.MQTT.Tests/ack_smoke_tests.cs#L84-L98' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_ack_mqtt_topic' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
68 changes: 68 additions & 0 deletions docs/guide/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,71 @@ public class When_message_is_sent : IAsyncLifetime
<!-- endSnippet -->

As you can see, we just have to start our application, attach a tracked session to it, and then wait for the message to be published. This way, we can test the whole process of the application, from the file change to the message publication, in a single test.

## Running Wolverine in "Solo" Mode <Badge type="tip" text="3.0" />

Wolverine's [leadership election](/guide/durability/leadership-and-troubleshooting.html#troubleshooting-and-leadership-election) process is necessary for distributing several background tasks in real life production,
but that subsystem can lead to some inconvenient sluggishness in [cold start times](https://dontpaniclabs.com/blog/post/2022/09/20/net-cold-starts/#:~:text=In%20software%20development%2C%20cold%20starts,have%20an%20increased%20start%20time.) in automation testing.

To sidestep that problem, you can direct Wolverine to run in "Solo" mode where the current process assumes that it's the
only running node and automatically starts up all known background tasks immediately.

To do so, you could do something like this in your main `Program` file:

<!-- snippet: sample_configuring_the_solo_mode -->
<a id='snippet-sample_configuring_the_solo_mode'></a>
```cs
var builder = Host.CreateApplicationBuilder();

builder.UseWolverine(opts =>
{
opts.Services.AddMarten("some connection string")

// This adds quite a bit of middleware for
// Marten
.IntegrateWithWolverine();

// You want this maybe!
opts.Policies.AutoApplyTransactions();

if (builder.Environment.IsDevelopment())
{
// But wait! Optimize Wolverine for usage as
// if there would never be more than one node running
opts.Durability.Mode = DurabilityMode.Solo;
}
});

using var host = builder.Build();
await host.StartAsync();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Samples/DocumentationSamples/DurabilityModes.cs#L63-L90' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_configuring_the_solo_mode' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or if you're using something like [WebHostFactory](https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-8.0) to
bootstrap your Wolverine application in an integration testing harness, you can use this helper to override Wolverine into being
"Solo":

<!-- snippet: sample_using_run_wolverine_in_solo_mode_with_extension -->
<a id='snippet-sample_using_run_wolverine_in_solo_mode_with_extension'></a>
```cs
// This is bootstrapping the actual application using
// its implied Program.Main() set up
// For non-Alba users, this is using IWebHostBuilder
Host = await AlbaHost.For<Program>(x =>
{
x.ConfigureServices(services =>
{
// Override the Wolverine configuration in the application
// to run the application in "solo" mode for faster
// testing cold starts
services.RunWolverineInSoloMode();

// And just for completion, disable all Wolverine external
// messaging transports
services.DisableAllExternalWolverineTransports();
});
});
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Http/Wolverine.Http.Tests/IntegrationContext.cs#L27-L47' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_run_wolverine_in_solo_mode_with_extension' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.3.0"/>
<PackageReference Include="FluentValidation" Version="11.10.0" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/Extensions/Wolverine.MemoryPack.Tests/end_to_end.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Wolverine.ComplianceTests;
using Wolverine.Tracking;
using Wolverine.Transports.Tcp;
using Wolverine.Util;
using Xunit;

namespace Wolverine.MemoryPack.Tests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MemoryPack" Version="1.9.10"/>
<PackageReference Include="MemoryPack" Version="1.21.3" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/Extensions/Wolverine.MessagePack.Tests/end_to_end.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Wolverine.ComplianceTests;
using Wolverine.Tracking;
using Wolverine.Transports.Tcp;
using Wolverine.Util;
using Xunit;

namespace Wolverine.MessagePack.Tests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MessagePack" Version="2.5.108"/>
<PackageReference Include="MessagePack" Version="2.5.172" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion src/Http/OpenApiDemonstrator/OpenApiDemonstrator.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.3.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.2" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Shouldly" Version="4.1.0" />
Expand Down
20 changes: 19 additions & 1 deletion src/Http/Wolverine.Http.Tests/IntegrationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,27 @@ public async Task InitializeAsync()
// use WebApplicationFactory and/or Alba for integration testing
OaktonEnvironment.AutoStartHost = true;

#region sample_using_run_wolverine_in_solo_mode_with_extension

// This is bootstrapping the actual application using
// its implied Program.Main() set up
Host = await AlbaHost.For<Program>(x => { });
// For non-Alba users, this is using IWebHostBuilder
Host = await AlbaHost.For<Program>(x =>
{
x.ConfigureServices(services =>
{
// Override the Wolverine configuration in the application
// to run the application in "solo" mode for faster
// testing cold starts
services.RunWolverineInSoloMode();

// And just for completion, disable all Wolverine external
// messaging transports
services.DisableAllExternalWolverineTransports();
});
});

#endregion
}

public Task DisposeAsync()
Expand Down
19 changes: 19 additions & 0 deletions src/Http/Wolverine.Http.Tests/override_durability_mode_to_solo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Wolverine.Runtime;

namespace Wolverine.Http.Tests;

public class override_durability_mode_to_solo : IntegrationContext
{
public override_durability_mode_to_solo(AppFixture fixture) : base(fixture)
{
}

[Fact]
public void verify_that_testing_helper_works()
{
Host.Services.GetRequiredService<IWolverineRuntime>()
.Options.Durability.Mode.ShouldBe(DurabilityMode.Solo);
}
}
1 change: 0 additions & 1 deletion src/Http/WolverineWebApi/WolverineWebApi.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.3.0" />
<PackageReference Include="Lamar.Diagnostics" Version="13.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.2" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
Expand Down
Loading
Loading