-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add retry support to testing framework (#33230)
- Loading branch information
Showing
6 changed files
with
116 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.ComponentModel; | ||
|
||
namespace Microsoft.AspNetCore.Testing | ||
{ | ||
/// <summary> | ||
/// Runs a test multiple times when it fails | ||
/// This can be used on an assembly, class, or method name. Requires using the AspNetCore test framework. | ||
/// </summary> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = false)] | ||
public sealed class RetryAttribute : Attribute | ||
{ | ||
public RetryAttribute(int maxRetries = 3) | ||
{ | ||
MaxRetries = maxRetries; | ||
} | ||
|
||
/// <summary> | ||
/// The maximum number of times to retry a failed test. Defaults to 3. | ||
/// </summary> | ||
public int MaxRetries { get; } | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Testing | ||
{ | ||
[Retry] | ||
public class RetryTest | ||
{ | ||
private static int _retryFailsUntil3 = 0; | ||
|
||
[Fact] | ||
public void RetryFailsUntil3() | ||
{ | ||
_retryFailsUntil3++; | ||
if (_retryFailsUntil3 != 2) throw new Exception("NOOOOOOOO"); | ||
} | ||
|
||
private static int _canOverrideRetries = 0; | ||
|
||
[Fact] | ||
[Retry(5)] | ||
public void CanOverrideRetries() | ||
{ | ||
_canOverrideRetries++; | ||
if (_canOverrideRetries != 5) throw new Exception("NOOOOOOOO"); | ||
} | ||
} | ||
} |