Last active
October 16, 2020 10:46
-
-
Save antonfirsov/d5cf9e01b065e58420080d0e9c31e548 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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