-
Couldn't load subscription status.
- Fork 1.1k
Closed
Labels
akka-testkitAkka.NET Testkit issuesAkka.NET Testkit issues
Milestone
Description
Version Information
Akka.TestKit.Xunit: 1.5.46
Describe the bug
When async message expectation operation is cancelled, the exception has one more level of nesting than expected.
To Reproduce
- Create a test class:
using System;
using System.Threading;
using System.Threading.Tasks;
using Akka.TestKit.Xunit;
using Shouldly;
using Xunit;
namespace Actors.Routers.Tests;
[Trait("Category", "Example")]
public class ExampleTests : TestKit
{
[Fact]
public async Task SynchronousExample()
{
var probe = CreateTestProbe();
using var stopper = new CancellationTokenSource();
stopper.Cancel();
var task = probe.ExpectMsgAsync<int>(
cancellationToken: stopper.Token).AsTask();
await Task.Delay(TimeSpan.FromSeconds(1)); // default timeout is 3 seconds
var inner = task.Exception.ShouldBeOfType<AggregateException>();
var superInner = inner.InnerException.ShouldBeOfType<AggregateException>();
superInner.InnerException.ShouldBeOfType<TaskCanceledException>();
}
[Fact]
public async Task AsynchronousExample()
{
var probe = CreateTestProbe();
using var stopper = new CancellationTokenSource();
stopper.Cancel();
try
{
await probe.ExpectMsgAsync<int>(
cancellationToken: stopper.Token);
}
catch (Exception caught)
{
var superInner = caught.ShouldBeOfType<AggregateException>();
superInner.InnerException.ShouldBeOfType<TaskCanceledException>();
}
}
}- Run the tests.
Expected behavior
I expected the tests to fail. I expected the operation to complete with some OperationCanceledException wrapped in AggregateException as with the most of .Net APIs.
Actual behavior
The tests pass. For some reason the method completes with TaskCanceledException wrapped in AggregateException wrapped in yet another AggregateException.
Environment
On Windows, dotnet 9.0.303, but I believe it does not matter.
Metadata
Metadata
Assignees
Labels
akka-testkitAkka.NET Testkit issuesAkka.NET Testkit issues