-
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,6 +170,41 @@ public async Task<int> OrchestrateTestHostExecutionAsync(CancellationToken cance | |
| finalArguments.Add($"--{RetryCommandLineOptionsProvider.RetryFailedTestsPipeNameOptionName}"); | ||
| finalArguments.Add(retryFailedTestsPipeServer.PipeName); | ||
|
|
||
| // When retrying, replace any existing test filter with --filter-uid for the failed tests | ||
| if (lastListOfFailedId is { Length: > 0 }) | ||
|
Evangelink marked this conversation as resolved.
|
||
| { | ||
| RemoveOption(finalArguments, TreeNodeFilterCommandLineOptionsProvider.TreenodeFilter); | ||
| RemoveOption(finalArguments, PlatformCommandLineProvider.FilterUidOptionKey); | ||
|
Evangelink marked this conversation as resolved.
|
||
|
|
||
| // Estimate command line length to avoid hitting OS limits (notably ~32K on Windows). | ||
| const int CommandLineLengthLimit = 30_000; | ||
| int predictedLength = 0; | ||
| foreach (string arg in finalArguments) | ||
| { | ||
| predictedLength += arg.Length + 1; | ||
| } | ||
|
|
||
| predictedLength += 2 + PlatformCommandLineProvider.FilterUidOptionKey.Length + 1; | ||
| foreach (string uid in lastListOfFailedId) | ||
| { | ||
| predictedLength += uid.Length + 1; | ||
| } | ||
|
|
||
| if (predictedLength <= CommandLineLengthLimit) | ||
| { | ||
| finalArguments.Add($"--{PlatformCommandLineProvider.FilterUidOptionKey}"); | ||
| finalArguments.AddRange(lastListOfFailedId); | ||
| } | ||
| else | ||
| { | ||
| // Use a response file to avoid exceeding command-line length limits. | ||
| string responseFilePath = Path.Combine(currentTryResultFolder, "retry-filter-uids.rsp"); | ||
| _fileSystem.CreateDirectory(currentTryResultFolder); | ||
| File.WriteAllText(responseFilePath, $"--{PlatformCommandLineProvider.FilterUidOptionKey} {string.Join(" ", lastListOfFailedId)}"); | ||
| finalArguments.Add($"@{responseFilePath}"); | ||
|
Evangelink marked this conversation as resolved.
Outdated
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. If this path has a space, we might fail. We need proper escaping.
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. Hmm, actually not, that's handled. It might still be worth to add a test |
||
| } | ||
|
Evangelink marked this conversation as resolved.
Evangelink marked this conversation as resolved.
|
||
| } | ||
|
|
||
| #if NET8_0_OR_GREATER | ||
| // On net8.0+, we can pass the arguments as a collection directly to ProcessStartInfo. | ||
| // When passing the collection, it's expected to be unescaped, so we pass what we have directly. | ||
|
|
@@ -351,4 +386,48 @@ private static int GetOptionArgumentIndex(string optionName, string[] executable | |
| index = Array.IndexOf(executableArgs, "--" + optionName); | ||
| return index >= 0 ? index : -1; | ||
| } | ||
|
|
||
| private static void RemoveOption(List<string> arguments, string optionName) | ||
| { | ||
| string longForm = $"--{optionName}"; | ||
| string shortForm = $"-{optionName}"; | ||
|
|
||
| // Remove all occurrences since options like --filter-uid can appear multiple times. | ||
| // Also handle --option=value and --option:value forms produced by the command-line parser. | ||
| while (true) | ||
| { | ||
| int idx = -1; | ||
| for (int i = 0; i < arguments.Count; i++) | ||
| { | ||
| string arg = arguments[i]; | ||
| if (arg == longForm || arg == shortForm | ||
| || arg.StartsWith(longForm + "=", StringComparison.Ordinal) || arg.StartsWith(longForm + ":", StringComparison.Ordinal) | ||
| || arg.StartsWith(shortForm + "=", StringComparison.Ordinal) || arg.StartsWith(shortForm + ":", StringComparison.Ordinal)) | ||
| { | ||
| idx = i; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (idx < 0) | ||
| { | ||
| break; | ||
| } | ||
|
|
||
| string found = arguments[idx]; | ||
| arguments.RemoveAt(idx); | ||
|
|
||
| // If the option used = or : separator, the value is inline — nothing more to remove. | ||
| if (found.Contains('=') || found.Contains(':')) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| // Otherwise, remove subsequent non-option arguments (the option's values). | ||
| while (idx < arguments.Count && !arguments[idx].StartsWith('-')) | ||
|
Evangelink marked this conversation as resolved.
|
||
| { | ||
| arguments.RemoveAt(idx); | ||
| } | ||
|
Evangelink marked this conversation as resolved.
Outdated
|
||
| } | ||
|
Evangelink marked this conversation as resolved.
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.