Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//-----------------------------------------------------------------------

using System;
using System.Threading.Tasks;
using Akka.TestKit.Xunit2.Internals;
using Xunit;

Expand Down Expand Up @@ -85,5 +86,25 @@ public void AssertEqual<T>(T expected, T actual, Func<T, T, bool> comparer, stri
if(!comparer(expected, actual))
throw AkkaEqualException.ForMismatchedValues(expected, actual, format, args);
}

public Exception AssertThrows(Action action)
{
return Assert.ThrowsAny<Exception>(action);
}

public TException AssertThrows<TException>(Action action) where TException : Exception
{
return Assert.ThrowsAny<TException>(action);
}

public async Task<Exception> AssertThrowsAsync(Func<Task> action)
{
return await Assert.ThrowsAnyAsync<Exception>(action);
}

public Task<TException> AssertThrowsAsync<TException>(Func<Task> action) where TException : Exception
{
return Assert.ThrowsAnyAsync<TException>(action);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ namespace Akka.TestKit
void AssertEqual<T>(T expected, T actual, string format = "", params object[] args);
void AssertEqual<T>(T expected, T actual, System.Func<T, T, bool> comparer, string format = "", params object[] args);
void AssertFalse(bool condition, string format = "", params object[] args);
System.Exception AssertThrows(System.Action action);
TException AssertThrows<TException>(System.Action action)
where TException : System.Exception;
System.Threading.Tasks.Task<System.Exception> AssertThrowsAsync(System.Func<System.Threading.Tasks.Task> action);
System.Threading.Tasks.Task<TException> AssertThrowsAsync<TException>(System.Func<System.Threading.Tasks.Task> action)
where TException : System.Exception;
void AssertTrue(bool condition, string format = "", params object[] args);
void Fail(string format = "", params object[] args);
}
Expand Down Expand Up @@ -613,13 +619,6 @@ namespace Akka.TestKit.Extensions
public class static TaskExtensions
{
public static System.Threading.Tasks.Task<bool> AwaitWithTimeout(this System.Threading.Tasks.Task parentTask, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken = null) { }
public static System.Threading.Tasks.Task ShouldCompleteWithin<T>(this System.Threading.Tasks.Task<T> task, T expected, System.TimeSpan timeout, string because = "", params object[] becauseArgs) { }
public static System.Threading.Tasks.Task<T> ShouldCompleteWithin<T>(this System.Threading.Tasks.Task<T> task, System.TimeSpan timeout, string because = "", params object[] becauseArgs) { }
public static System.Threading.Tasks.Task ShouldCompleteWithin(this System.Threading.Tasks.Task task, System.TimeSpan timeout, string because = "", params object[] becauseArgs) { }
public static System.Threading.Tasks.Task ShouldThrowWithin<T>(this System.Threading.Tasks.Task task, T expected, System.TimeSpan timeout, string because = "", params object[] becauseArgs)
where T : System.Exception { }
public static System.Threading.Tasks.Task<T> ShouldThrowWithin<T>(this System.Threading.Tasks.Task task, System.TimeSpan timeout, string because = "", params object[] becauseArgs)
where T : System.Exception { }
public static System.Threading.Tasks.Task<T> WithTimeout<T>(this System.Threading.Tasks.Task<T> parentTask, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken = null) { }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ namespace Akka.TestKit
void AssertEqual<T>(T expected, T actual, string format = "", params object[] args);
void AssertEqual<T>(T expected, T actual, System.Func<T, T, bool> comparer, string format = "", params object[] args);
void AssertFalse(bool condition, string format = "", params object[] args);
System.Exception AssertThrows(System.Action action);
TException AssertThrows<TException>(System.Action action)
where TException : System.Exception;
System.Threading.Tasks.Task<System.Exception> AssertThrowsAsync(System.Func<System.Threading.Tasks.Task> action);
System.Threading.Tasks.Task<TException> AssertThrowsAsync<TException>(System.Func<System.Threading.Tasks.Task> action)
where TException : System.Exception;
void AssertTrue(bool condition, string format = "", params object[] args);
void Fail(string format = "", params object[] args);
}
Expand Down Expand Up @@ -613,13 +619,6 @@ namespace Akka.TestKit.Extensions
public class static TaskExtensions
{
public static System.Threading.Tasks.Task<bool> AwaitWithTimeout(this System.Threading.Tasks.Task parentTask, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken = null) { }
public static System.Threading.Tasks.Task ShouldCompleteWithin<T>(this System.Threading.Tasks.Task<T> task, T expected, System.TimeSpan timeout, string because = "", params object[] becauseArgs) { }
public static System.Threading.Tasks.Task<T> ShouldCompleteWithin<T>(this System.Threading.Tasks.Task<T> task, System.TimeSpan timeout, string because = "", params object[] becauseArgs) { }
public static System.Threading.Tasks.Task ShouldCompleteWithin(this System.Threading.Tasks.Task task, System.TimeSpan timeout, string because = "", params object[] becauseArgs) { }
public static System.Threading.Tasks.Task ShouldThrowWithin<T>(this System.Threading.Tasks.Task task, T expected, System.TimeSpan timeout, string because = "", params object[] becauseArgs)
where T : System.Exception { }
public static System.Threading.Tasks.Task<T> ShouldThrowWithin<T>(this System.Threading.Tasks.Task task, System.TimeSpan timeout, string because = "", params object[] becauseArgs)
where T : System.Exception { }
public static System.Threading.Tasks.Task<T> WithTimeout<T>(this System.Threading.Tasks.Task<T> parentTask, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken = null) { }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ namespace Akka.TestKit.Xunit2
public void AssertEqual<T>(T expected, T actual, string format = "", params object[] args) { }
public void AssertEqual<T>(T expected, T actual, System.Func<T, T, bool> comparer, string format = "", params object[] args) { }
public void AssertFalse(bool condition, string format = "", params object[] args) { }
public System.Exception AssertThrows(System.Action action) { }
public TException AssertThrows<TException>(System.Action action)
where TException : System.Exception { }
public System.Threading.Tasks.Task<System.Exception> AssertThrowsAsync(System.Func<System.Threading.Tasks.Task> action) { }
public System.Threading.Tasks.Task<TException> AssertThrowsAsync<TException>(System.Func<System.Threading.Tasks.Task> action)
where TException : System.Exception { }
public void AssertTrue(bool condition, string format = "", params object[] args) { }
public void Fail(string format = "", params object[] args) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ namespace Akka.TestKit.Xunit2
public void AssertEqual<T>(T expected, T actual, string format = "", params object[] args) { }
public void AssertEqual<T>(T expected, T actual, System.Func<T, T, bool> comparer, string format = "", params object[] args) { }
public void AssertFalse(bool condition, string format = "", params object[] args) { }
public System.Exception AssertThrows(System.Action action) { }
public TException AssertThrows<TException>(System.Action action)
where TException : System.Exception { }
public System.Threading.Tasks.Task<System.Exception> AssertThrowsAsync(System.Func<System.Threading.Tasks.Task> action) { }
public System.Threading.Tasks.Task<TException> AssertThrowsAsync<TException>(System.Func<System.Threading.Tasks.Task> action)
where TException : System.Exception { }
public void AssertTrue(bool condition, string format = "", params object[] args) { }
public void Fail(string format = "", params object[] args) { }
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/Akka.Cluster.Tests/ClusterLogSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ await EventFilter
tcs.TrySetResult(true);
});
_cluster.Join(_selfAddress);
await tcs.Task.ShouldCompleteWithin(10.Seconds());
await tcs.Task.WaitAsync(10.Seconds());
});
}

Expand All @@ -92,7 +92,7 @@ await EventFilter
tcs.TrySetResult(true);
});
_cluster.Down(_selfAddress);
await tcs.Task.ShouldCompleteWithin(10.Seconds());
await tcs.Task.WaitAsync(10.Seconds());
});
}
}
Expand Down Expand Up @@ -124,9 +124,9 @@ public ClusterLogVerboseDefaultSpec(ITestOutputHelper output)
public async Task A_cluster_must_not_log_verbose_cluster_events_by_default()
{
_cluster.Settings.LogInfoVerbose.ShouldBeFalse();
await JoinAsync(upLogMessage).ShouldThrowWithin<XunitException>(11.Seconds());
await AssertThrowsAsync<XunitException>(() => JoinAsync(upLogMessage)).WaitAsync(11.Seconds());
await AwaitUpAsync();
await DownAsync(downLogMessage).ShouldThrowWithin<XunitException>(11.Seconds());
await AssertThrowsAsync<XunitException>(() => DownAsync(downLogMessage)).WaitAsync(11.Seconds());
}
}

Expand Down
30 changes: 15 additions & 15 deletions src/core/Akka.Cluster.Tests/ClusterSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public async Task A_cluster_must_complete_LeaveAsync_task_upon_being_removed()
var removed = (ClusterEvent.MemberRemoved)await probe.FishForMessageAsync(m => m is ClusterEvent.MemberRemoved);
removed.PreviousStatus.Should().BeEquivalentTo(MemberStatus.Exiting);

await leaveTask.ShouldCompleteWithin(RemainingOrDefault);
await leaveTask.WaitAsync(RemainingOrDefault);

// A second call for LeaveAsync should complete immediately (should be the same task as before)
Cluster.Get(sys2).LeaveAsync().IsCompleted.Should().BeTrue();
Expand Down Expand Up @@ -235,7 +235,7 @@ await WithinAsync(TimeSpan.FromSeconds(10), async () =>
});

// LeaveAsync() task expected to complete immediately
await _cluster.LeaveAsync().ShouldCompleteWithin(RemainingOrDefault);
await _cluster.LeaveAsync().WaitAsync(RemainingOrDefault);
}

[Fact]
Expand Down Expand Up @@ -324,14 +324,14 @@ public async Task A_cluster_must_be_able_to_JoinAsync()

try
{
await _cluster.JoinAsync(_selfAddress).ShouldCompleteWithin(timeout);
await _cluster.JoinAsync(_selfAddress).WaitAsync(timeout);
LeaderActions();
// Member should already be up
_cluster.Subscribe(TestActor, ClusterEvent.InitialStateAsEvents, typeof(ClusterEvent.IMemberEvent));
await ExpectMsgAsync<ClusterEvent.MemberUp>();

// join second time - response should be immediate success
await _cluster.JoinAsync(_selfAddress).ShouldCompleteWithin(100.Milliseconds());
await _cluster.JoinAsync(_selfAddress).WaitAsync(100.Milliseconds());
}
finally
{
Expand All @@ -346,7 +346,7 @@ await Awaiting(async () =>
await task;
})
.Should().ThrowAsync<ClusterJoinFailedException>()
.ShouldCompleteWithin(timeout);
.WaitAsync(timeout);
}

[Fact]
Expand All @@ -370,7 +370,7 @@ await Awaiting(async () =>
await task;
})
.Should().ThrowAsync<ClusterJoinFailedException>()
.ShouldCompleteWithin(15.Seconds());
.WaitAsync(15.Seconds());
}
finally
{
Expand All @@ -385,14 +385,14 @@ public async Task A_cluster_must_be_able_to_join_async_to_seed_nodes()

try
{
await _cluster.JoinSeedNodesAsync(new[] { _selfAddress }).ShouldCompleteWithin(timeout);
await _cluster.JoinSeedNodesAsync(new[] { _selfAddress }).WaitAsync(timeout);
LeaderActions();
// Member should already be up
_cluster.Subscribe(TestActor, ClusterEvent.InitialStateAsEvents, typeof(ClusterEvent.IMemberEvent));
await ExpectMsgAsync<ClusterEvent.MemberUp>();

// join second time - response should be immediate success
await _cluster.JoinSeedNodesAsync(new[] { _selfAddress }).ShouldCompleteWithin(100.Milliseconds());
await _cluster.JoinSeedNodesAsync(new[] { _selfAddress }).WaitAsync(100.Milliseconds());
}
finally
{
Expand All @@ -407,7 +407,7 @@ await Awaiting(async () =>
await ExpectMsgAsync<ClusterEvent.MemberRemoved>();
})
.Should().ThrowAsync<ClusterJoinFailedException>()
.ShouldCompleteWithin(timeout);
.WaitAsync(timeout);
}

[Fact]
Expand All @@ -431,7 +431,7 @@ await Awaiting(async () =>
await task;
})
.Should().ThrowAsync<ClusterJoinFailedException>()
.ShouldCompleteWithin(15.Seconds());
.WaitAsync(15.Seconds());
}
finally
{
Expand Down Expand Up @@ -477,7 +477,7 @@ public async Task A_cluster_must_leave_via_CoordinatedShutdownRun()
var removed = (ClusterEvent.MemberRemoved)await probe.FishForMessageAsync(m => m is ClusterEvent.MemberRemoved);
new [] {MemberStatus.Exiting, MemberStatus.Leaving}.Should().Contain(removed.PreviousStatus);

await task.ShouldCompleteWithin(3.Seconds());
await task.WaitAsync(3.Seconds());
}
finally
{
Expand Down Expand Up @@ -537,7 +537,7 @@ public async Task A_cluster_must_terminate_ActorSystem_via_leave_CoordinatedShut
var probe = CreateTestProbe(sys2);
Cluster.Get(sys2).Subscribe(probe.Ref, typeof(ClusterEvent.IMemberEvent));
await probe.ExpectMsgAsync<ClusterEvent.CurrentClusterState>();
await Cluster.Get(sys2).JoinAsync(Cluster.Get(sys2).SelfAddress).ShouldCompleteWithin(10.Seconds());
await Cluster.Get(sys2).JoinAsync(Cluster.Get(sys2).SelfAddress).WaitAsync(10.Seconds());
await probe.ExpectMsgAsync<ClusterEvent.MemberUp>();

Cluster.Get(sys2).Leave(Cluster.Get(sys2).SelfAddress);
Expand All @@ -546,7 +546,7 @@ public async Task A_cluster_must_terminate_ActorSystem_via_leave_CoordinatedShut
// MemberExited might not be published before MemberRemoved
var removed = (ClusterEvent.MemberRemoved)await probe.FishForMessageAsync(m => m is ClusterEvent.MemberRemoved);
removed.PreviousStatus.Should().BeEquivalentTo(MemberStatus.Exiting);
await sys2.WhenTerminated.ShouldCompleteWithin(10.Seconds());
await sys2.WhenTerminated.WaitAsync(10.Seconds());
Cluster.Get(sys2).IsTerminated.Should().BeTrue();
CoordinatedShutdown.Get(sys2).ShutdownReason.Should().BeOfType<CoordinatedShutdown.ClusterLeavingReason>();
}
Expand All @@ -572,14 +572,14 @@ public async Task A_cluster_must_terminate_ActorSystem_via_Down_CoordinatedShutd
var probe = CreateTestProbe(sys3);
Cluster.Get(sys3).Subscribe(probe.Ref, typeof(ClusterEvent.IMemberEvent));
await probe.ExpectMsgAsync<ClusterEvent.CurrentClusterState>();
await Cluster.Get(sys3).JoinAsync(Cluster.Get(sys3).SelfAddress).ShouldCompleteWithin(10.Seconds());
await Cluster.Get(sys3).JoinAsync(Cluster.Get(sys3).SelfAddress).WaitAsync(10.Seconds());
await probe.ExpectMsgAsync<ClusterEvent.MemberUp>();

Cluster.Get(sys3).Down(Cluster.Get(sys3).SelfAddress);

await probe.ExpectMsgAsync<ClusterEvent.MemberDowned>();
await probe.ExpectMsgAsync<ClusterEvent.MemberRemoved>();
await sys3.WhenTerminated.ShouldCompleteWithin(10.Seconds());
await sys3.WhenTerminated.WaitAsync(10.Seconds());
Cluster.Get(sys3).IsTerminated.Should().BeTrue();
CoordinatedShutdown.Get(sys3).ShutdownReason.Should().BeOfType<CoordinatedShutdown.ClusterDowningReason>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected override void OnReceive(object message)
private async Task<IActorRef> Here()
{
var identity = await Sys.ActorSelection(RootB / "user" / "echo").Ask<ActorIdentity>(new Identify(null))
.ShouldCompleteWithin(DefaultTimeout);
.WaitAsync(DefaultTimeout);
return identity.Subject;
}

Expand All @@ -158,7 +158,7 @@ private Task<bool> Throttle(ThrottleTransportAdapter.Direction direction, Thrott
Sys.AsInstanceOf<ExtendedActorSystem>().Provider.AsInstanceOf<RemoteActorRefProvider>().Transport;

return transport.ManagementCommand(new SetThrottle(rootBAddress, direction, mode))
.ShouldCompleteWithin(DefaultTimeout);
.WaitAsync(DefaultTimeout);
}

private Task<bool> Disassociate()
Expand All @@ -168,7 +168,7 @@ private Task<bool> Disassociate()
Sys.AsInstanceOf<ExtendedActorSystem>().Provider.AsInstanceOf<RemoteActorRefProvider>().Transport;

return transport.ManagementCommand(new ForceDisassociate(rootBAddress))
.ShouldCompleteWithin(DefaultTimeout);
.WaitAsync(DefaultTimeout);
}

#endregion
Expand All @@ -188,7 +188,7 @@ public async Task ThrottlerTransportAdapter_must_maintain_average_message_rate()
await Throttle(
ThrottleTransportAdapter.Direction.Send,
new Remote.Transport.TokenBucket(PingPacketSize * 4, BytesPerSecond, 0, 0))
.ShouldCompleteWithin(true, TimeSpan.FromSeconds(3));
.WaitAsync(TimeSpan.FromSeconds(3));

var here = await Here();
var tester = Sys.ActorOf(Props.Create(() => new ThrottlingTester(here, TestActor)));
Expand All @@ -199,7 +199,7 @@ await Throttle(
time.Should().BeGreaterThan(TotalTime - 12);

await Throttle(ThrottleTransportAdapter.Direction.Send, Unthrottled.Instance)
.ShouldCompleteWithin(true, TimeSpan.FromSeconds(3));
.WaitAsync(TimeSpan.FromSeconds(3));
}

[Fact]
Expand All @@ -214,15 +214,15 @@ public async Task ThrottlerTransportAdapter_must_survive_blackholing()
MuteDeadLetters(_systemB, typeof(ThrottlingTester.Lost));

await Throttle(ThrottleTransportAdapter.Direction.Both, Blackhole.Instance)
.ShouldCompleteWithin(true, 3.Seconds());
.WaitAsync(3.Seconds());

here.Tell(new ThrottlingTester.Lost("BlackHole 2"));
await ExpectNoMsgAsync(TimeSpan.FromSeconds(1));
await Disassociate().ShouldCompleteWithin(true, TimeSpan.FromSeconds(3));
await Disassociate().WaitAsync(TimeSpan.FromSeconds(3));
await ExpectNoMsgAsync(TimeSpan.FromSeconds(1));

await Throttle(ThrottleTransportAdapter.Direction.Both, Unthrottled.Instance)
.ShouldCompleteWithin(true, TimeSpan.FromSeconds(3));
.WaitAsync(TimeSpan.FromSeconds(3));

// after we remove the Blackhole we can't be certain of the state
// of the connection, repeat until success
Expand Down
Loading
Loading