-
Notifications
You must be signed in to change notification settings - Fork 292
Simplify retry extension logic to use built-in filters #7511
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
Open
Evangelink
wants to merge
4
commits into
main
Choose a base branch
from
dev/amauryleve/simpler-retry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+156
−152
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
50 changes: 0 additions & 50 deletions
50
src/Platform/Microsoft.Testing.Extensions.Retry/RetryExecutionFilterFactory.cs
This file was deleted.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -205,6 +205,56 @@ public async Task RetryFailedTests_PassingFromFirstTime_UsingTestTarget_MoveFile | |
| } | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DynamicData(nameof(TargetFrameworks.NetForDynamicData), typeof(TargetFrameworks))] | ||
| public async Task RetryFailedTests_WithPreexistingFilterUid_ReplacesFilterOnRetry(string tfm) | ||
| { | ||
| var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); | ||
| string resultDirectory = Path.Combine(testHost.DirectoryName, Guid.NewGuid().ToString("N")); | ||
|
|
||
| // Use --filter-uid to select tests 1 and 2. Test 1 will fail on first attempt, pass on second. | ||
| TestHostResult testHostResult = await testHost.ExecuteAsync( | ||
| $"--retry-failed-tests 3 --filter-uid 1 --filter-uid 2 --results-directory {resultDirectory}", | ||
| new() | ||
| { | ||
| { EnvironmentVariableConstants.TESTINGPLATFORM_TELEMETRY_OPTOUT, "1" }, | ||
| { "METHOD1", "1" }, | ||
| { "RESULTDIR", resultDirectory }, | ||
| }, | ||
| cancellationToken: TestContext.CancellationToken); | ||
|
|
||
| testHostResult.AssertExitCodeIs(ExitCodes.Success); | ||
| testHostResult.AssertOutputContains("Tests suite completed successfully in 2 attempts"); | ||
|
|
||
| // The retry attempt should only retry the failed test (UID 1), not all originally filtered tests. | ||
| testHostResult.AssertOutputContains("Tests suite failed, total failed tests: 1, exit code: 2, attempt: 1/4"); | ||
| } | ||
Evangelink marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [TestMethod] | ||
| [DynamicData(nameof(TargetFrameworks.NetForDynamicData), typeof(TargetFrameworks))] | ||
| public async Task RetryFailedTests_WithPreexistingTreenodeFilter_ReplacesFilterOnRetry(string tfm) | ||
| { | ||
| var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); | ||
| string resultDirectory = Path.Combine(testHost.DirectoryName, Guid.NewGuid().ToString("N")); | ||
|
|
||
| // Use --treenode-filter to select all tests. Test 1 will fail on first attempt, pass on second. | ||
| TestHostResult testHostResult = await testHost.ExecuteAsync( | ||
| $"--retry-failed-tests 3 --treenode-filter /** --results-directory {resultDirectory}", | ||
| new() | ||
| { | ||
| { EnvironmentVariableConstants.TESTINGPLATFORM_TELEMETRY_OPTOUT, "1" }, | ||
| { "METHOD1", "1" }, | ||
| { "RESULTDIR", resultDirectory }, | ||
| }, | ||
| cancellationToken: TestContext.CancellationToken); | ||
|
|
||
| testHostResult.AssertExitCodeIs(ExitCodes.Success); | ||
| testHostResult.AssertOutputContains("Tests suite completed successfully in 2 attempts"); | ||
|
|
||
| // The retry attempt should only retry the failed test (UID 1), not all tests matching the tree filter. | ||
| testHostResult.AssertOutputContains("Tests suite failed, total failed tests: 1, exit code: 2, attempt: 1/4"); | ||
| } | ||
|
|
||
| public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) | ||
| { | ||
| public string TargetAssetPath => GetAssetPath(AssetName); | ||
|
|
@@ -252,6 +302,7 @@ public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture. | |
| using Microsoft.Testing.Platform.Extensions.Messages; | ||
| using Microsoft.Testing.Platform.Extensions.TestFramework; | ||
| using Microsoft.Testing.Platform.MSBuild; | ||
| using Microsoft.Testing.Platform.Requests; | ||
| using Microsoft.Testing.Platform.Services; | ||
|
|
||
| public class Program | ||
|
|
@@ -306,46 +357,60 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context) | |
| string resultDir = Environment.GetEnvironmentVariable("RESULTDIR")!; | ||
| bool crash = Environment.GetEnvironmentVariable("CRASH") == "1"; | ||
|
|
||
| var uidFilter = (context.Request as TestExecutionRequest)?.Filter as TestNodeUidListFilter; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering how did this test work before? How was it respecting the retry filter? |
||
|
|
||
| var testMethod1Identifier = new TestMethodIdentifierProperty(string.Empty, string.Empty, "DummyClassName", "TestMethod1", 0, Array.Empty<string>(), string.Empty); | ||
| var testMethod2Identifier = new TestMethodIdentifierProperty(string.Empty, string.Empty, "DummyClassName", "TestMethod2", 0, Array.Empty<string>(), string.Empty); | ||
| var testMethod3Identifier = new TestMethodIdentifierProperty(string.Empty, string.Empty, "DummyClassName", "TestMethod3", 0, Array.Empty<string>(), string.Empty); | ||
|
|
||
| if (TestMethod1(fail, resultDir, crash)) | ||
| if (IsIncluded(uidFilter, "1")) | ||
| { | ||
| await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, | ||
| new TestNode() { Uid = "1", DisplayName = "TestMethod1", Properties = new(PassedTestNodeStateProperty.CachedInstance, testMethod1Identifier) })); | ||
| } | ||
| else | ||
| { | ||
| await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, | ||
| new TestNode() { Uid = "1", DisplayName = "TestMethod1", Properties = new(new FailedTestNodeStateProperty(), testMethod1Identifier) })); | ||
| if (TestMethod1(fail, resultDir, crash)) | ||
| { | ||
| await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, | ||
| new TestNode() { Uid = "1", DisplayName = "TestMethod1", Properties = new(PassedTestNodeStateProperty.CachedInstance, testMethod1Identifier) })); | ||
| } | ||
| else | ||
| { | ||
| await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, | ||
| new TestNode() { Uid = "1", DisplayName = "TestMethod1", Properties = new(new FailedTestNodeStateProperty(), testMethod1Identifier) })); | ||
| } | ||
| } | ||
|
|
||
| if (TestMethod2(fail, resultDir)) | ||
| if (IsIncluded(uidFilter, "2")) | ||
| { | ||
| await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, | ||
| new TestNode() { Uid = "2", DisplayName = "TestMethod2", Properties = new(PassedTestNodeStateProperty.CachedInstance, testMethod2Identifier) })); | ||
| } | ||
| else | ||
| { | ||
| await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, | ||
| new TestNode() { Uid = "2", DisplayName = "TestMethod2", Properties = new(new FailedTestNodeStateProperty(), testMethod2Identifier) })); | ||
| if (TestMethod2(fail, resultDir)) | ||
| { | ||
| await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, | ||
| new TestNode() { Uid = "2", DisplayName = "TestMethod2", Properties = new(PassedTestNodeStateProperty.CachedInstance, testMethod2Identifier) })); | ||
| } | ||
| else | ||
| { | ||
| await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, | ||
| new TestNode() { Uid = "2", DisplayName = "TestMethod2", Properties = new(new FailedTestNodeStateProperty(), testMethod2Identifier) })); | ||
| } | ||
| } | ||
|
|
||
| if (TestMethod3(fail, resultDir)) | ||
| { | ||
| await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, | ||
| new TestNode() { Uid = "3", DisplayName = "TestMethod3", Properties = new(PassedTestNodeStateProperty.CachedInstance, testMethod3Identifier) })); | ||
| } | ||
| else | ||
| if (IsIncluded(uidFilter, "3")) | ||
| { | ||
| await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, | ||
| new TestNode() { Uid = "3", DisplayName = "TestMethod3", Properties = new(new FailedTestNodeStateProperty(), testMethod3Identifier) })); | ||
| if (TestMethod3(fail, resultDir)) | ||
| { | ||
| await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, | ||
| new TestNode() { Uid = "3", DisplayName = "TestMethod3", Properties = new(PassedTestNodeStateProperty.CachedInstance, testMethod3Identifier) })); | ||
| } | ||
| else | ||
| { | ||
| await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, | ||
| new TestNode() { Uid = "3", DisplayName = "TestMethod3", Properties = new(new FailedTestNodeStateProperty(), testMethod3Identifier) })); | ||
| } | ||
| } | ||
|
|
||
| context.Complete(); | ||
| } | ||
|
|
||
| private static bool IsIncluded(TestNodeUidListFilter? filter, string uid) | ||
| => filter is null || filter.TestNodeUids.Any(n => n.Value == uid); | ||
|
|
||
| private bool TestMethod1(bool fail, string resultDir, bool crash) | ||
| { | ||
| if (crash) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.