forked from akkadotnet/akka.net
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ReceiveAsync feature to Akka.TestKit TestActorRef (akkadotnet#6281)
Co-authored-by: Aaron Stannard <[email protected]>
- Loading branch information
1 parent
de55b33
commit 5605d83
Showing
4 changed files
with
157 additions
and
10 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/core/Akka.TestKit.Tests/TestActorRefTests/ExceptionHandling.cs
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,61 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="ExceptionHandling.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using static FluentAssertions.FluentActions; | ||
|
||
namespace Akka.TestKit.Tests.TestActorRefTests | ||
{ | ||
public class ExceptionHandling: TestKit.Xunit2.TestKit | ||
{ | ||
private class GiveError | ||
{ } | ||
|
||
private class GiveErrorAsync | ||
{ } | ||
|
||
private class ExceptionActor : ReceiveActor | ||
{ | ||
public ExceptionActor() | ||
{ | ||
Receive<GiveError>((b) => throw new Exception("WAT")); | ||
|
||
ReceiveAsync<GiveErrorAsync>(async (b) => | ||
{ | ||
await Task.Delay(TimeSpan.FromSeconds(0.1)); | ||
throw new Exception("WATASYNC"); | ||
}); | ||
} | ||
} | ||
|
||
public ExceptionHandling(ITestOutputHelper helper) : base("akka.loglevel = debug", helper) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void GetException() | ||
{ | ||
var props = Props.Create<ExceptionActor>(); | ||
var subject = new TestActorRef<ExceptionActor>(Sys, props, null, "testA"); | ||
Invoking(() => subject.Receive(new GiveError())) | ||
.Should().Throw<Exception>().WithMessage("WAT"); | ||
} | ||
|
||
[Fact] | ||
public async Task GetExceptionAsync() | ||
{ | ||
var props = Props.Create<ExceptionActor>(); | ||
var subject = new TestActorRef<ExceptionActor>(Sys, props, null, "testB"); | ||
await Awaiting(() => subject.ReceiveAsync(new GiveErrorAsync())) | ||
.Should().ThrowAsync<Exception>().WithMessage("WATASYNC"); | ||
} | ||
} | ||
} |
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
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
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