Skip to content

Commit

Permalink
Add repro for #6990
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkatufus committed Dec 8, 2023
1 parent b7c2871 commit 4a21dad
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/core/Akka.TestKit.Tests/TestKitBaseTests/ExpectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.TestKit;
using FluentAssertions;
using FluentAssertions.Extensions;
using Xunit;
using Xunit.Sdk;
using static FluentAssertions.FluentActions;
Expand Down Expand Up @@ -162,5 +164,50 @@ await Awaiting(async () =>
.ToListAsync();
}).Should().ThrowAsync<XunitException>().WithMessage("Timeout (*");
}

// We're testing the sync version of ExpectMsg, never change this to async
[Fact(DisplayName = "#6990 ExpectMsg should respect timeout args")]
public void ExpectMsgRespectsTimeout()
{
var bridge = Sys.ActorOf(Props.Create<BridgeActor<Message>>());
bridge.Tell(Props.Create<DelayedPingActor>(), TestActor);
var response = ExpectMsg<TestMessage<Message>>(100.Seconds());
response.Message.Payload.Should().Be("PING");
}

private record Message
{
public string Payload { get; init; }
}
private record TestMessage<T>(T Message);

private class BridgeActor<T>: ReceiveActor where T: Message, new()
{
public BridgeActor()
{
ReceiveAsync<Props>(async props =>
{
var sender = Sender;
var childActor = Context.ActorOf(props);
var response = await childActor.Ask<string>("PING");
response.Should().Be("PING");
sender.Tell(new TestMessage<T>(new T{ Payload = response }));
});
}
}

private class DelayedPingActor: ReceiveActor
{
public DelayedPingActor()
{
ReceiveAsync<string>(async msg =>
{
var sender = Sender;
await Task.Delay(6.Seconds());
sender.Tell(msg);
});
}

}
}
}

0 comments on commit 4a21dad

Please sign in to comment.