Skip to content

Instantly share code, notes, and snippets.

@antonfirsov
Last active October 16, 2020 10:46
Show Gist options
  • Save antonfirsov/d5cf9e01b065e58420080d0e9c31e548 to your computer and use it in GitHub Desktop.
Save antonfirsov/d5cf9e01b065e58420080d0e9c31e548 to your computer and use it in GitHub Desktop.
internal static class RetryHelper
{
public static async Task ExecuteAsync(Func<Task> test, int maxAttempts = 5, Func<int, int> backoffFunc = null);
}
// Throws custom exceptions, which trigger retries:
internal static class TryAssert
{
public static void Equal(...);
public static void True(...);
public static void False(...);
}
public class TestClass
{
[Fact]
public async SomeTest()
{
await RetryHelper.ExecuteAsync(() => {
// To make sure we don't do unintentional retries, failing standard Xunit asserts shall trigger test failures:
Assert.True(...);
// We need to pick the cases when we want to retry explicitly:
TryAssert.True(...);
}, 10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment