Skip to content

Commit

Permalink
Fix ExpectAsync(0) implementation (#4782)
Browse files Browse the repository at this point in the history
* Added failing spec

* Fixed assertion

Co-authored-by: Aaron Stannard <aaron@petabridge.com>
  • Loading branch information
IgorFedchenko and Aaronontheweb authored Feb 12, 2021
1 parent a6ea829 commit 179b916
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,26 @@ public void Expect_0_events_Should_work()
}).Should().Throw<Exception>("Expected 0 events");
}

[Fact]
public async Task ExpectAsync_0_events_Should_work()
{
Exception ex = null;
try
{
await EventFilter.Error().ExpectAsync(0, async () =>
{
await Task.Delay(100); // bug only happens when error is not logged instantly
Log.Error("something");
});
}
catch (Exception e)
{
ex = e;
}

ex.Should().NotBeNull("Expected 0 errors logged, but there are error logs");
}

[Fact]
public void Messages_can_be_muted()
{
Expand Down
13 changes: 11 additions & 2 deletions src/core/Akka.TestKit/EventFilter/Internal/EventFilterApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,17 @@ protected async Task<bool> AwaitDoneAsync(TimeSpan timeout, int? expectedOccurre
if(expectedOccurrences.HasValue)
{
var expected = expectedOccurrences.GetValueOrDefault();
await _testkit.AwaitConditionNoThrowAsync(() => matchedEventHandler.ReceivedCount >= expected, timeout);
return matchedEventHandler.ReceivedCount == expected;
if (expected > 0)
{
await _testkit.AwaitConditionNoThrowAsync(() => matchedEventHandler.ReceivedCount >= expected, timeout);
return matchedEventHandler.ReceivedCount == expected;
}
else
{
// if expecting no events to arrive - assert that given condition will never match
var foundEvent = await _testkit.AwaitConditionNoThrowAsync(() => matchedEventHandler.ReceivedCount > 0, timeout);
return foundEvent == false;
}
}
return true;
}
Expand Down

0 comments on commit 179b916

Please sign in to comment.