From d3016f2140baad7b9663a092cf0abd3e74ca0acf Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Mon, 13 Feb 2023 21:16:32 +0100 Subject: [PATCH] RemoteExecutor does not support getting application arguments, Process.WaitForExitAsync is available only on .NET 7+ --- .../CancelOnProcessTerminationTests.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/System.CommandLine.Tests/Invocation/CancelOnProcessTerminationTests.cs b/src/System.CommandLine.Tests/Invocation/CancelOnProcessTerminationTests.cs index 2c037b8b45..fac1ec06a6 100644 --- a/src/System.CommandLine.Tests/Invocation/CancelOnProcessTerminationTests.cs +++ b/src/System.CommandLine.Tests/Invocation/CancelOnProcessTerminationTests.cs @@ -29,8 +29,9 @@ public enum Signals [Fact] public async Task CancellableHandler_is_cancelled_on_process_termination() { - // the feature is supported on Windows, but it's simply harder to send SIGINT to test it properly - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + // The feature is supported on Windows, but it's simply harder to send SIGINT to test it properly. + // Same for macOS, where RemoteExecutor does not support getting application arguments. + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { await StartKillAndVerify(new[] { "--infiniteDelay", "false" }, Signals.SIGINT, GracefulExitCode); } @@ -39,7 +40,7 @@ public async Task CancellableHandler_is_cancelled_on_process_termination() [Fact] public async Task NonCancellableHandler_is_interrupted_on_process_termination() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { await StartKillAndVerify(new[] { "--infiniteDelay", "true" }, Signals.SIGTERM, SIGTERM_EXIT_CODE); } @@ -95,16 +96,9 @@ private async Task StartKillAndVerify(string[] args, Signals signal, int expecte kill(process.Id, (int)signal).Should().Be(0); // Verify the process terminates timely - try - { - using CancellationTokenSource cts = new (TimeSpan.FromSeconds(10)); - await process.WaitForExitAsync(cts.Token); - } - catch (OperationCanceledException) + if (!process.WaitForExit(TimeSpan.FromSeconds(10))) { process.Kill(); - - throw; } // Verify the process exit code