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

fix: poll w/ solely until predicate #147

Merged
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
2 changes: 1 addition & 1 deletion src/Arcus.Testing.Core/Poll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public async Task<TResult> StartAsync()
Policy.HandleResult((TResult r) =>
{
results.Add(r);
return _untilTargets.Count > 0 && _untilTargets.Any(untilTarget => untilTarget(r));
return !_untilTargets.All(untilTarget => untilTarget(r));
}).Or<TException>(ex =>
{
exceptions.Add(ex);
Expand Down
21 changes: 21 additions & 0 deletions src/Arcus.Testing.Tests.Unit/Core/PollTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Bogus;
Expand Down Expand Up @@ -63,6 +64,26 @@ public async Task Poll_WithDiffExceptionThanUnavailableTarget_FailsDirectlyWithD
await FailsByExceptionAsync(async () => await Poll.Target<object, ApplicationException>(AlwaysFailsResultAsync).MinTimeFrame());
}

[Fact]
public async Task Poll_WithUntilPredicate_SucceedsAfterThirdTime()
{
// Arrange
var stopwatch = Stopwatch.StartNew();

int index = 0;
TimeSpan timeout = TimeSpan.FromSeconds(1);
TimeSpan interval = TimeSpan.FromMilliseconds(200);

// Act
await Poll.Target(() => Task.FromResult(++index))
.Until(result => result >= 3)
.Every(interval)
.Timeout(timeout);

// Assert
Assert.True(interval + interval <= stopwatch.Elapsed, "stopwatch should at least run until two intervals");
}

[Fact]
public async Task Poll_WithNegativeUntilTargetPredicate_FailsWithDescription()
{
Expand Down
Loading