Skip to content

Commit

Permalink
Update tests to expect RemoteExecutor to check exit code (#64133)
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung authored Jan 24, 2022
1 parent 070b7d8 commit db21974
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ await Host.CreateDefaultBuilder()
services.AddHostedService<EnsureEnvironmentExitCodeWorker>();
})
.RunConsoleAsync();
});
}, new RemoteInvokeOptions() { ExpectedExitCode = 124 });

// TODO: Remove once https://github.com/dotnet/arcade/issues/5865 is resolved
remoteHandle.Process.WaitForExit();

Assert.Equal(124, remoteHandle.Process.ExitCode);
}

Expand All @@ -130,6 +130,9 @@ await Task.Run(() =>
[ActiveIssue("https://github.com/dotnet/runtime/issues/34582", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
public void EnsureEnvironmentExitDoesntHang()
{
// SIGTERM is only handled on net6.0+, so the workaround to "clobber" the exit code is still in place on .NET Framework
int expectedExitCode = PlatformDetection.IsNetFramework ? 0 : 125;

using var remoteHandle = RemoteExecutor.Invoke(async () =>
{
await Host.CreateDefaultBuilder()
Expand All @@ -139,12 +142,11 @@ await Host.CreateDefaultBuilder()
services.AddHostedService<EnsureEnvironmentExitDoesntHangWorker>();
})
.RunConsoleAsync();
}, new RemoteInvokeOptions() { TimeOut = 30_000 }); // give a 30 second time out, so if this does hang, it doesn't hang for the full timeout
}, new RemoteInvokeOptions() { TimeOut = 30_000, ExpectedExitCode = expectedExitCode }); // give a 30 second time out, so if this does hang, it doesn't hang for the full timeout

Assert.True(remoteHandle.Process.WaitForExit(30_000), "The hosted process should have exited within 30 seconds");

// SIGTERM is only handled on net6.0+, so the workaround to "clobber" the exit code is still in place on NetFramework
int expectedExitCode = PlatformDetection.IsNetFramework ? 0 : 125;
// TODO: Remove once https://github.com/dotnet/arcade/issues/5865 is resolved
Assert.Equal(expectedExitCode, remoteHandle.Process.ExitCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,7 @@ static void remoteWrite(string fileName, string text)
}
},
fileName,
text,
new RemoteInvokeOptions() { ExpectedExitCode = 0 }).Dispose();
text).Dispose();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Console/tests/CancelKeyPress.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void ExitDetectionNotBlockedByHandler()
// Release CancelKeyPress
mre.Set();
}).Dispose();
}, new RemoteInvokeOptions() { ExpectedExitCode = 130 }).Dispose();
}

private void HandlerInvokedForSignal(int signalOuter, bool redirectStandardInput)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void SigTermExitCode(int? exitCodeOnSigterm)

RemoteInvokeOptions options = new RemoteInvokeOptions();
options.StartInfo.RedirectStandardOutput = true;
options.CheckExitCode = false;
using (RemoteInvokeHandle remoteExecution = RemoteExecutor.Invoke(action, exitCodeOnSigterm?.ToString() ?? string.Empty, options))
{
Process process = remoteExecution.Process;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void VariousNestingAndVisibilityLevelsAreSupported()
public static void Converters_AndTypeInfoCreator_NotRooted_WhenMetadataNotPresent()
{
RemoteExecutor.Invoke(
new Action(() =>
() =>
{
object[] objArr = new object[] { new MyStruct() };
Expand Down Expand Up @@ -56,8 +56,7 @@ static void AssertFieldNull(string fieldName, JsonSerializerOptions? optionsInst
Assert.NotNull(fieldInfo);
Assert.Null(fieldInfo.GetValue(optionsInstance));
}
}),
new RemoteInvokeOptions() { ExpectedExitCode = 0 }).Dispose();
}).Dispose();
}

[Fact]
Expand Down

0 comments on commit db21974

Please sign in to comment.