diff --git a/src/core/Akka.Tests/Actor/AskSpec.cs b/src/core/Akka.Tests/Actor/AskSpec.cs index d6389f71c4d..7935fbf461d 100644 --- a/src/core/Akka.Tests/Actor/AskSpec.cs +++ b/src/core/Akka.Tests/Actor/AskSpec.cs @@ -282,6 +282,23 @@ public async Task Bugfix5204_should_allow_null_response_without_error() resp.Should().BeNullOrEmpty(); } + /// + /// Reproduction for https://github.com/akkadotnet/akka.net/issues/7254 + /// + [Fact] + public async Task Bugfix7254_should_throw_error_when_expecting_object_type() + { + const string textExceptionMessage = "THIS IS TEST"; + + var actor = Sys.ActorOf(act => act.ReceiveAny((_, context) => + { + context.Sender.Tell(new Status.Failure(new Exception(textExceptionMessage))); + })); + + var ex = await Assert.ThrowsAsync(async () => await actor.Ask("answer")); + ex.Message.ShouldBe(textExceptionMessage); + } + [Fact] public void AskDoesNotDeadlockWhenWaitForResultInGuiApplication() { diff --git a/src/core/Akka.Tests/Actor/InboxSpec.cs b/src/core/Akka.Tests/Actor/InboxSpec.cs index b1a19321f1d..7abbc4c94dd 100644 --- a/src/core/Akka.Tests/Actor/InboxSpec.cs +++ b/src/core/Akka.Tests/Actor/InboxSpec.cs @@ -157,9 +157,7 @@ public void Select_WithClient_should_update_Client_and_copy_the_rest_of_the_prop public async Task Inbox_Receive_will_timeout_gracefully_if_timeout_is_already_expired() { var task = _inbox.ReceiveAsync(TimeSpan.FromSeconds(-1)); - Assert.True(await task.AwaitWithTimeout(TimeSpan.FromMilliseconds(1000)), "Receive did not complete in time."); - Assert.IsType(task.Result); + await Assert.ThrowsAnyAsync(() => task.AwaitWithTimeout(TimeSpan.FromMilliseconds(1000))); } } } - diff --git a/src/core/Akka/Actor/ActorRef.cs b/src/core/Akka/Actor/ActorRef.cs index 8be973a515d..fda9af4a400 100644 --- a/src/core/Akka/Actor/ActorRef.cs +++ b/src/core/Akka/Actor/ActorRef.cs @@ -113,23 +113,23 @@ protected override void TellInternal(object message, IActorRef sender) case ISystemMessage msg: handled = _result.TrySetException(new InvalidOperationException($"system message of type '{msg.GetType().Name}' is invalid for {nameof(FutureActorRef)}")); break; - case T t: - handled = _result.TrySetResult(t); - break; - case null: - handled = _result.TrySetResult(default); - break; - case Status.Failure f: + case Status.Failure f when typeof(T) != typeof(Status.Failure): handled = _result.TrySetException(f.Cause ?? new TaskCanceledException("Task cancelled by actor via Failure message.")); break; #pragma warning disable CS0618 // for backwards compatibility - case Failure f: + case Failure f when !typeof(Failure).IsAssignableFrom(typeof(T)): handled = _result.TrySetException(f.Exception ?? new TaskCanceledException("Task cancelled by actor via Failure message.")); #pragma warning restore CS0618 break; + case T t: + handled = _result.TrySetResult(t); + break; + case null: + handled = _result.TrySetResult(default); + break; default: _ = _result.TrySetException(new ArgumentException( $"Received message of type [{message.GetType()}] - Ask expected message of type [{typeof(T)}]"));