diff --git a/src/Cli/dotnet/Commands/Test/MTP/TestApplicationHandler.cs b/src/Cli/dotnet/Commands/Test/MTP/TestApplicationHandler.cs index 8db706d7c382..9735d0ab72b2 100644 --- a/src/Cli/dotnet/Commands/Test/MTP/TestApplicationHandler.cs +++ b/src/Cli/dotnet/Commands/Test/MTP/TestApplicationHandler.cs @@ -15,6 +15,7 @@ internal sealed class TestApplicationHandler private readonly Dictionary _testSessionEventCountPerSessionUid = new(); private (string? TargetFramework, string? Architecture, string ExecutionId)? _handshakeInfo; + private bool _receivedTestHostHandshake; public TestApplicationHandler(TerminalTestReporter output, TestModule module, TestOptions options) { @@ -62,6 +63,7 @@ internal void OnHandshakeReceived(HandshakeMessage handshakeMessage, bool gotSup // https://github.com/microsoft/testfx/blob/2a9a353ec2bb4ce403f72e8ba1f29e01e7cf1fd4/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs#L87-L97 if (hostType == "TestHost") { + _receivedTestHostHandshake = true; // AssemblyRunStarted counts "retry count", and writes to terminal "(Try ) Running tests from " // So, we want to call it only for test host, and not for test host controller (or orchestrator, if in future it will handshake as well) // Calling it for both test host and test host controllers means we will count retries incorrectly, and will messages twice. @@ -263,8 +265,10 @@ internal bool HasMismatchingTestSessionEventCount() internal void OnTestProcessExited(int exitCode, string outputData, string errorData) { - if (_handshakeInfo.HasValue) + if (_receivedTestHostHandshake && _handshakeInfo.HasValue) { + // If we received a handshake from TestHostController but not from TestHost, + // call HandshakeFailure instead of AssemblyRunCompleted _output.AssemblyRunCompleted(_handshakeInfo.Value.ExecutionId, exitCode, outputData, errorData); } else