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

Convert Akka.TestKit.Tests.TestKitBaseTests ExpectTests and IgnoreMessagesTests to async #5876

Merged
Show file tree
Hide file tree
Changes from 2 commits
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
33 changes: 21 additions & 12 deletions src/core/Akka.TestKit.Tests/TestKitBaseTests/ExpectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,61 @@
//-----------------------------------------------------------------------

using System;
using System.Linq;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.TestKit;
using FluentAssertions;
using Xunit;
using Xunit.Sdk;
using static FluentAssertions.FluentActions;

namespace Akka.Testkit.Tests.TestKitBaseTests
namespace Akka.TestKit.Tests.TestKitBaseTests
{
public class ExpectTests : AkkaSpec
{
[Fact]
public void ExpectMsgAllOf_should_receive_correct_messages()
public async Task ExpectMsgAllOfAsync_should_receive_correct_messages()
{
TestActor.Tell("1");
TestActor.Tell("2");
TestActor.Tell("3");
TestActor.Tell("4");
ExpectMsgAllOf(new []{ "3", "1", "4", "2"}).ShouldOnlyContainInOrder("1", "2", "3", "4");
await ExpectMsgAllOfAsync(new []{ "3", "1", "4", "2"})
.ShouldOnlyContainInOrderAsync("1", "2", "3", "4");
}

[Fact]
public void ExpectMsgAllOf_should_fail_when_receiving_unexpected()
public async Task ExpectMsgAllOfAsync_should_fail_when_receiving_unexpected()
{
TestActor.Tell("1");
TestActor.Tell("2");
TestActor.Tell("Totally unexpected");
TestActor.Tell("3");
Invoking(() => ExpectMsgAllOf(new[] { "3", "1", "2" })).Should()
.Throw<XunitException>();
await Awaiting(async () =>
{
await ExpectMsgAllOfAsync(new[] { "3", "1", "2" }).ToListAsync();
}).Should().ThrowAsync<XunitException>().WithMessage("not found [*");
}

[Fact]
public void ExpectMsgAllOf_should_timeout_when_not_receiving_any_messages()
public async Task ExpectMsgAllOfAsync_should_timeout_when_not_receiving_any_messages()
{
Invoking(() => ExpectMsgAllOf(TimeSpan.FromMilliseconds(100), new[] { "3", "1", "2" })).Should()
.Throw<XunitException>();
await Awaiting(async () =>
{
await ExpectMsgAllOfAsync(TimeSpan.FromMilliseconds(100), new[] { "3", "1", "2" }).ToListAsync();
}).Should().ThrowAsync<XunitException>().WithMessage("Timeout (*");
}

[Fact]
public void ExpectMsgAllOf_should_timeout_if_to_few_messages()
public async Task ExpectMsgAllOfAsync_should_timeout_if_to_few_messages()
{
TestActor.Tell("1");
TestActor.Tell("2");
Invoking(() => ExpectMsgAllOf(TimeSpan.FromMilliseconds(100), new[] { "3", "1", "2" })).Should()
.Throw<XunitException>();
await Awaiting(async () =>
{
await ExpectMsgAllOfAsync(TimeSpan.FromMilliseconds(100), new[] { "3", "1", "2" }).ToListAsync();
}).Should().ThrowAsync<XunitException>().WithMessage("Timeout (*");
}

}
Expand Down
26 changes: 13 additions & 13 deletions src/core/Akka.TestKit.Tests/TestKitBaseTests/IgnoreMessagesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.TestKit;
using Xunit;
using FluentAssertions;

namespace Akka.TestKit.Tests.TestKitBaseTests
{
Expand All @@ -25,39 +25,39 @@ public IgnoredMessage(string ignoreMe = null)
}

[Fact]
public void IgnoreMessages_should_ignore_messages()
public async Task IgnoreMessages_should_ignore_messages()
{
IgnoreMessages(o => o is int && (int)o == 1);
IgnoreMessages(o => o is int i && i == 1);
TestActor.Tell(1);
TestActor.Tell("1");
String.Equals((string)ReceiveOne(), "1").ShouldBeTrue();
HasMessages.ShouldBeFalse();
(await ReceiveOneAsync()).Should().Be("1");
HasMessages.Should().BeFalse();
}

[Fact]
public void IgnoreMessages_should_ignore_messages_T()
public async Task IgnoreMessages_should_ignore_messages_T()
{
IgnoreMessages<IgnoredMessage>();

TestActor.Tell("1");
TestActor.Tell(new IgnoredMessage(), TestActor);
TestActor.Tell("2");
ReceiveN(2).ShouldOnlyContainInOrder("1", "2");
HasMessages.ShouldBeFalse();
await ReceiveNAsync(2).ShouldOnlyContainInOrderAsync("1", "2");
HasMessages.Should().BeFalse();
}

[Fact]
public void IgnoreMessages_should_ignore_messages_T_with_Func()
public async Task IgnoreMessages_should_ignore_messages_T_with_Func()
{
IgnoreMessages<IgnoredMessage>(m => String.IsNullOrWhiteSpace(m.IgnoreMe));
IgnoreMessages<IgnoredMessage>(m => string.IsNullOrWhiteSpace(m.IgnoreMe));

var msg = new IgnoredMessage("not ignored!");

TestActor.Tell("1");
TestActor.Tell(msg, TestActor);
TestActor.Tell("2");
ReceiveN(3).ShouldOnlyContainInOrder("1", msg, "2");
HasMessages.ShouldBeFalse();
await ReceiveNAsync(3).ShouldOnlyContainInOrderAsync("1", msg, "2");
HasMessages.Should().BeFalse();
}
}
}