Fix StartAndForget_StartsProcessAndReturnsValidPid by mapping ProcessStartInfo.Arguments for the string+args overload#127116
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process |
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/c84ad3a6-2269-49a1-be61-284e675daa50 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/c84ad3a6-2269-49a1-be61-284e675daa50 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
StartAndForget_StartsProcessAndReturnsValidPid by replacing flaky HasExited check
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/10d359fd-34fe-4733-b49c-ea5c0be6bc42 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
From the logs:
System.Diagnostics.Tests.StartAndForgetTests.StartAndForget_StartsProcessAndReturnsValidPid(useProcessStartInfo: False) [FAIL]
Assert.True() Failure
Expected: True
Actual: False
Stack Trace:
/_/src/libraries/System.Diagnostics.Process/tests/StartAndForget.cs(30,0): at System.Diagnostics.Tests.StartAndForgetTests.StartAndForget_StartsProcessAndReturnsValidPid(Boolean useProcessStartInfo)
at System.Object.InvokeStub_StartAndForgetTests.StartAndForget_StartsProcessAndReturnsValidPid(Object, Span`1)
/_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs(95,0): at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
It fails when useProcessStartInfo: False and I think I know why. RemoteExecutor is using dotnet to invoke the process using Arguments, not ArgumentsList. When we pass the ArgumentsList here:
we pass an empty string, and invoke dotnet which prints sth like this:
PS C:\Users\adsitnik> dotnet
Usage: dotnet [path-to-application]
Usage: dotnet [commands]
path-to-application:
The path to an application .dll file to execute.
commands:
-h|--help Display help.
--info Display .NET information.
--list-runtimes [--arch <arch>] Display the installed runtimes matching the host or specified architecture. Example architectures: arm64, x64, x86.
--list-sdks [--arch <arch>] Display the installed SDKs matching the host or specified architecture. Example architectures: arm64, x64, x86.
And exits. That is why the process is sometimes gone when we get to HasExited check.
@copilot please do the following:
There was a problem hiding this comment.
Pull request overview
Fixes intermittent failures in StartAndForget_StartsProcessAndReturnsValidPid by ensuring the string + args overload receives arguments derived from ProcessStartInfo.Arguments (which RemoteExecutor populates), rather than relying on ArgumentList (which may be empty).
Changes:
- Maps
ProcessStartInfo.Argumentsinto aList<string>for theProcess.StartAndForget(string, IList<string>?)path. - Adds a local helper to split the
Argumentsstring into an argument list for the test.
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/1762a9d2-5f02-4434-abcf-19188faf5214 Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Head branch was pushed to by a user without write access
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/06fbf653-1bca-4454-9808-3281ddb2b7aa Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
StartAndForget_StartsProcessAndReturnsValidPidwas failing intermittently foruseProcessStartInfo: falsebecause the test passedtemplate.StartInfo.ArgumentList, whileRemoteExecutorpopulatesArguments. This could launchdotnetwith effectively empty/incorrect arguments and exit early.What changed
HasExitedassertion path and cleanup.useProcessStartInfo: falsebranch to maptemplate.StartInfo.ArgumentsintoList<string>and pass that list toProcess.StartAndForget(string, IList<string>?).StartAndForget.cs(based on the referenced logic from PR Add new process management APIs to SafeProcessHandle #124375) to split theArgumentsstring into a list.MapToArgumentList(template.StartInfo)directly in theStartAndForgetcall so mapping is only computed whenuseProcessStartInfoisfalse.MapToArgumentListexplaining why this helper is needed in this test (RemoteExecutorusesArguments, while this overload requires a list).Code shape
System.Diagnostics.Processtests for this area with no failures.