Skip to content

Commit

Permalink
Make updates to FishUntil
Browse files Browse the repository at this point in the history
Implement nitpicks from akkadotnet#5430
  • Loading branch information
Aaronontheweb committed Dec 15, 2021
1 parent 7e48e35 commit b368dc6
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/core/Akka.TestKit/TestKitBase_Receive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,27 @@ public T FishForMessage<T>(Predicate<T> isMessage, TimeSpan? max = null, string
var left = end - Now;
var msg = ReceiveOne(left);
_assertions.AssertTrue(msg != null, "Timeout ({0}) during fishForMessage{1}", maxValue, string.IsNullOrEmpty(hint) ? "" : ", hint: " + hint);
if (msg is T && isMessage((T)msg))
if (msg is T msg1 && isMessage(msg1))
{
return (T)msg;
return msg1;
}
}
}

/// <summary>
/// Receives messages until <paramref name="max"/>. Ignores all messages except for a message of type <typeparamref name="T"/>. Asserts that all messages are not of the of type <typeparamref name="T"/>. Note that when comparing types, inheritance is ignored, in other words, only perfectly matching types are asserted.
/// Receives messages until <paramref name="max"/>.
///
/// Ignores all messages except for a message of type <typeparamref name="T"/>.
/// Asserts that all messages are not of the of type <typeparamref name="T"/>.
/// Note that when comparing types, inheritance is ignored, in other words, only perfectly matching types are asserted.
/// </summary>
/// <typeparam name="T">The type that the message is not supposed to be.</typeparam>
/// <param name="probe"></param>
/// <param name="max"></param>
public async static Task InverseFishForMessage<T>(TestProbe probe, TimeSpan? max = null)
/// <param name="max">Optional. The maximum wait duration. Defaults to <see cref="RemainingOrDefault"/> when unset.</param>
public async Task FishUntilMessage<T>(TimeSpan? max = null)
{
await Task.Run(() =>
{
probe.ReceiveWhile<object>(max: max, shouldIgnore: x =>
ReceiveWhile<object>(max: max, shouldIgnore: x =>
{
x.Should().NotBeOfType<T>();
return false; // we are not returning anything
Expand Down

0 comments on commit b368dc6

Please sign in to comment.