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

Stabilize AddHedging_IntegrationTest test #1644

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,45 +36,33 @@ public async Task AddHedging_IntegrationTest()
{
int hedgingCount = 0;

var strategy = _builder
.AddHedging(new()
var strategy = _builder.AddHedging(new()
{
MaxHedgedAttempts = 4,
Delay = System.Threading.Timeout.InfiniteTimeSpan,
ShouldHandle = args => args.Outcome.Result switch
{
MaxHedgedAttempts = 4,
Delay = TimeSpan.FromMilliseconds(20),
ShouldHandle = args => args.Outcome.Result switch
{
"error" => PredicateResult.True(),
_ => PredicateResult.False()
},
ActionGenerator = args =>
{
return async () =>
{
await Task.Delay(25, args.ActionContext.CancellationToken);

if (args.AttemptNumber == 3)
{
return Outcome.FromResult("success");
}

return Outcome.FromResult("error");
};
},
OnHedging = args =>
"error" => PredicateResult.True(),
_ => PredicateResult.False()
},
ActionGenerator = args =>
{
return () => args.AttemptNumber switch
{
hedgingCount++;
return default;
}
})
.Build();

var result = await strategy.ExecuteAsync(async token =>
{
await Task.Delay(25, token);
return "error";
});
3 => Outcome.FromResultAsValueTask("success"),
_ => Outcome.FromResultAsValueTask("error")
};
},
OnHedging = args =>
{
Interlocked.Increment(ref hedgingCount);
return default;
}
})
.Build();

var result = await strategy.ExecuteAsync(token => new ValueTask<string>("error"));
result.Should().Be("success");
hedgingCount.Should().Be(4);
hedgingCount.Should().Be(3);
}
}
Loading