Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Akka.Tests.Routing tests to async/await - TailChoppingSpec #5815

Merged
merged 2 commits into from
Apr 5, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/core/Akka.Tests/Routing/TailChoppingSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Xunit;
using FluentAssertions;
using FluentAssertions.Extensions;
using System.Threading.Tasks;

namespace Akka.Tests.Routing
{
Expand All @@ -30,7 +31,7 @@ public TailChopTestActor(TimeSpan sleepTime)
{
_sleepTime = sleepTime;

Receive<string>(command =>
ReceiveAsync<string>( async command =>
{
switch (command)
{
Expand All @@ -42,7 +43,7 @@ public TailChopTestActor(TimeSpan sleepTime)
break;
default:
_times++;
Thread.Sleep(_sleepTime);
await Task.Delay(_sleepTime);
Sender.Tell("ack");
break;
}
Expand Down Expand Up @@ -107,7 +108,7 @@ public void Tail_chopping_group_router_must_deliver_a_broadcast_message_using_te
}

[Fact]
public void Tail_chopping_group_router_must_return_response_from_second_actor_after_inactivity_from_first_one()
public async Task Tail_chopping_group_router_must_return_response_from_second_actor_after_inactivity_from_first_one()
{
var actor1 = Sys.ActorOf(Props.Create(() => new TailChopTestActor(1.Milliseconds())), "Actor1");
var actor2 = Sys.ActorOf(Props.Create(() => new TailChopTestActor(1.Milliseconds())), "Actor2");
Expand All @@ -117,16 +118,17 @@ public void Tail_chopping_group_router_must_return_response_from_second_actor_af
var routedActor = Sys.ActorOf(new TailChoppingGroup(paths, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(50)).Props());

probe.Send(routedActor, "");
probe.ExpectMsg("ack");
await probe.ExpectMsgAsync("ack");

var actorList = new List<IActorRef> { actor1, actor2 };
OneOfShouldEqual(1, actorList)(x => (int)x.Ask("times").Result).Should().BeTrue();

routedActor.Tell(new Broadcast("stop"));
}

[Fact(Skip = "Skip until fix from https://github.com/akkadotnet/akka.net/pull/3790 merged")]
public void Tail_chopping_group_router_must_throw_exception_if_no_result_will_arrive_within_the_given_time()
//[Fact(Skip = "Skip until fix from https://github.com/akkadotnet/akka.net/pull/3790 merged")]
[Fact]
public async Task Tail_chopping_group_router_must_throw_exception_if_no_result_will_arrive_within_the_given_time()
{
var actor1 = Sys.ActorOf(Props.Create(() => new TailChopTestActor(1500.Milliseconds())), "Actor3");
var actor2 = Sys.ActorOf(Props.Create(() => new TailChopTestActor(1500.Milliseconds())), "Actor4");
Expand All @@ -136,7 +138,7 @@ public void Tail_chopping_group_router_must_throw_exception_if_no_result_will_ar
var routedActor = Sys.ActorOf(new TailChoppingGroup(paths, TimeSpan.FromMilliseconds(300), TimeSpan.FromMilliseconds(50)).Props());

probe.Send(routedActor, "");
var failure = probe.ExpectMsg<Status.Failure>();
var failure = await probe.ExpectMsgAsync<Status.Failure>();
failure.Cause.Should().BeOfType<AskTimeoutException>();

var actorList = new List<IActorRef> { actor1, actor2 };
Expand All @@ -146,7 +148,7 @@ public void Tail_chopping_group_router_must_throw_exception_if_no_result_will_ar
}

[Fact]
public void Tail_chopping_group_router_must_reply_ASAP()
public async Task Tail_chopping_group_router_must_reply_ASAP()
{
var actor1 = Sys.ActorOf(Props.Create(() => new TailChopTestActor(1000.Milliseconds())), "Actor5");
var actor2 = Sys.ActorOf(Props.Create(() => new TailChopTestActor(4000.Milliseconds())), "Actor6");
Expand All @@ -156,7 +158,7 @@ public void Tail_chopping_group_router_must_reply_ASAP()
var routedActor = Sys.ActorOf(new TailChoppingGroup(paths, TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(100)).Props());

probe.Send(routedActor, "");
probe.ExpectMsg("ack", 2.Seconds());
await probe.ExpectMsgAsync("ack", 2.Seconds());

routedActor.Tell(new Broadcast("stop"));
}
Expand Down