forked from akkadotnet/Akka.Hosting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure
AkkaHostedService
failures are always visible (akkadotnet…
…#494) * Make sure `AkkaHostedService` failures are always visible close akkadotnet#470 - application crashes and exits should always be explicitly logged someplace where they can be seen regardless of logging configuration. * Re-throw exception on application startup --------- Co-authored-by: Gregorius Soedharmo <arkatufus@yahoo.com>
- Loading branch information
1 parent
fb80b87
commit 401e020
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using static FluentAssertions.FluentActions; | ||
|
||
namespace Akka.Hosting.Tests; | ||
|
||
public class StartFailureSpec | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
|
||
public StartFailureSpec(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldThrowWhenActorSystemFailedToStart() | ||
{ | ||
// arrange | ||
var host = new HostBuilder() | ||
.ConfigureLogging(builder => | ||
{ | ||
builder.ClearProviders(); | ||
builder.AddProvider(new XUnitLoggerProvider(_output, LogLevel.Debug)); | ||
}) | ||
.ConfigureServices(services => | ||
{ | ||
services.AddAkka("MySys", (builder, provider) => | ||
{ | ||
builder.AddStartup((_, _) => throw new TestException("BOOM")); | ||
}); | ||
}) | ||
.Build(); | ||
|
||
await Awaiting(async () => await host.StartAsync()).Should() | ||
.ThrowExactlyAsync<TestException>().WithMessage("BOOM"); | ||
} | ||
|
||
private class TestException: Exception | ||
{ | ||
public TestException(string? message) : base(message) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters