Skip to content

Commit

Permalink
Make Expect(0) to throw when any event received (#4771)
Browse files Browse the repository at this point in the history
* Added failing spec

* Fixed expecting code

* Restart CI
  • Loading branch information
IgorFedchenko authored Feb 9, 2021
1 parent 6ecf4da commit 076d8de
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ protected virtual async Task HandleDeleteMessagesTo(DeleteMessagesTo req, TComma
catch (Exception cause)
{
var response = new DeleteMessagesFailure(cause, toSequenceNr);
req.PersistentActor.Tell(response, ActorRefs.NoSender);
req.PersistentActor.Tell(response, ActorRefs.NoSender);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.TestKit.Tests/Akka.TestKit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Threading.Tasks;
using Akka.Event;
using FluentAssertions;
using Xunit;
using Xunit.Sdk;

Expand Down Expand Up @@ -126,8 +127,6 @@ public void Do_not_intercept_messages_when_source_does_not_match()
TestSuccessful = true;
}



[Fact]
public void Specified_numbers_of_messagesan_be_intercepted()
{
Expand All @@ -139,6 +138,17 @@ public void Specified_numbers_of_messagesan_be_intercepted()
TestSuccessful = true;
}

[Fact]
public void Expect_0_events_Should_work()
{
this.Invoking(_ =>
{
EventFilter.Error().Expect(0, () =>
{
Log.Error("something");
});
}).Should().Throw<Exception>("Expected 0 events");
}

[Fact]
public void Messages_can_be_muted()
Expand Down
15 changes: 12 additions & 3 deletions src/core/Akka.TestKit/EventFilter/Internal/EventFilterApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,20 @@ protected async Task<T> InterceptAsync<T>(Func<Task<T>> func, ActorSystem system
/// <returns>TBD</returns>
protected bool AwaitDone(TimeSpan timeout, int? expectedOccurrences, MatchedEventHandler matchedEventHandler)
{
if(expectedOccurrences.HasValue)
if (expectedOccurrences.HasValue)
{
var expected = expectedOccurrences.GetValueOrDefault();
_testkit.AwaitConditionNoThrow(() => matchedEventHandler.ReceivedCount >= expected, timeout);
return matchedEventHandler.ReceivedCount == expected;
if (expected > 0)
{
_testkit.AwaitConditionNoThrow(() => matchedEventHandler.ReceivedCount >= expected, timeout);
return matchedEventHandler.ReceivedCount == expected;
}
else
{
// if expecting no events to arrive - assert that given condition will never match
var foundEvent = _testkit.AwaitConditionNoThrow(() => matchedEventHandler.ReceivedCount > 0, timeout);
return foundEvent == false;
}
}
return true;
}
Expand Down

0 comments on commit 076d8de

Please sign in to comment.