-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some tests back pressure for msbuild (#2152)
- Loading branch information
1 parent
761b4cc
commit 00333e1
Showing
8 changed files
with
95 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
26 changes: 24 additions & 2 deletions
26
test/Utilities/Microsoft.Testing.TestInfrastructure/RetryHelper.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Polly; | ||
|
||
namespace Microsoft.Testing.TestInfrastructure; | ||
|
||
public class RetryHelper | ||
{ | ||
public static async Task RetryAsync(Func<Task> action, uint times, TimeSpan every, Func<Exception, bool>? predicate = null) | ||
{ | ||
await action(); | ||
await Policy.Handle<Exception>(exception => | ||
{ | ||
if (predicate is null) | ||
{ | ||
return true; | ||
} | ||
return predicate(exception); | ||
}) | ||
.WaitAndRetryAsync((int)times, _ => every) | ||
.ExecuteAsync(action); | ||
} | ||
|
||
public static async Task<T> RetryAsync<T>(Func<Task<T>> action, uint times, TimeSpan every, Func<Exception, bool>? predicate = null) | ||
{ | ||
return await action(); | ||
return await Policy.Handle<Exception>(exception => | ||
{ | ||
if (predicate is null) | ||
{ | ||
return true; | ||
} | ||
return predicate(exception); | ||
}) | ||
.WaitAndRetryAsync((int)times, _ => every) | ||
.ExecuteAsync(action); | ||
} | ||
} |
This file contains 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