Skip to content

Commit ccff236

Browse files
Youssef1313Copilot
andauthored
Fix handshaking of dotnet test for MTP (#50513)
Co-authored-by: Copilot <[email protected]>
1 parent ae2e197 commit ccff236

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/Cli/dotnet/Commands/Test/Terminal/TerminalTestReporter.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,10 @@ private static void AppendAssemblyLinkTargetFrameworkAndArchitecture(ITerminal t
710710
if (targetFramework != null)
711711
{
712712
terminal.Append(targetFramework);
713-
terminal.Append('|');
713+
if (architecture != null)
714+
{
715+
terminal.Append('|');
716+
}
714717
}
715718

716719
if (architecture != null)
@@ -822,6 +825,15 @@ internal void AssemblyRunCompleted(string executionId,
822825

823826
internal void HandshakeFailure(string assemblyPath, string targetFramework, int exitCode, string outputData, string errorData)
824827
{
828+
if (_isHelp)
829+
{
830+
// Ignore handshake failures for help for now.
831+
// So far, MTP doesn't handshake on help.
832+
// MTP should be updated for that, however, but this workaround will likely need to stay
833+
// here for a bit to keep compatibility with older MTP versions. It doesn't have to stay for too long though.
834+
return;
835+
}
836+
825837
Interlocked.Increment(ref _handshakeFailuresCount);
826838
_terminalWithProgress.WriteToTerminal(terminal =>
827839
{

src/Cli/dotnet/Commands/Test/TestApplicationEventHandlers.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,22 @@ internal sealed class TestApplicationsEventHandlers(TerminalTestReporter output)
1717

1818
public void OnHandshakeReceived(object sender, HandshakeArgs args)
1919
{
20+
var testApplication = (TestApplication)sender;
21+
// Today, it's 1.0.0 in MTP.
22+
// https://github.com/microsoft/testfx/blob/516eebb3c9b7e81eb2677c00b3d0b7867d8acb33/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Constants.cs#L40
23+
var supportedProtocolVersions = args.Handshake.Properties[HandshakeMessagePropertyNames.SupportedProtocolVersions];
24+
if (supportedProtocolVersions != "1.0.0" && !supportedProtocolVersions.Split(';').Contains("1.0.0"))
25+
{
26+
_output.HandshakeFailure(testApplication.Module.TargetPath, string.Empty, ExitCode.GenericFailure, $"Supported protocol versions '{supportedProtocolVersions}' doesn't include '1.0.0' which is not supported by the current .NET SDK.", string.Empty);
27+
}
28+
2029
var hostType = args.Handshake.Properties[HandshakeMessagePropertyNames.HostType];
2130
// https://github.com/microsoft/testfx/blob/2a9a353ec2bb4ce403f72e8ba1f29e01e7cf1fd4/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs#L87-L97
2231
if (hostType == "TestHost")
2332
{
2433
// AssemblyRunStarted counts "retry count", and writes to terminal "(Try <number-of-try>) Running tests from <assembly>"
2534
// 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)
2635
// Calling it for both test host and test host controllers means we will count retries incorrectly, and will messages twice.
27-
var testApplication = (TestApplication)sender;
2836
var executionId = args.Handshake.Properties[HandshakeMessagePropertyNames.ExecutionId];
2937
var instanceId = args.Handshake.Properties[HandshakeMessagePropertyNames.InstanceId];
3038
var arch = args.Handshake.Properties[HandshakeMessagePropertyNames.Architecture]?.ToLower();

src/Cli/dotnet/Commands/Test/TestingPlatformCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ private void InitializeHelpActionQueue(int degreeOfParallelism, TestOptions test
151151
{
152152
_actionQueue = new(degreeOfParallelism, buildOptions, async (TestApplication testApp) =>
153153
{
154+
testApp.HandshakeReceived += _eventHandlers.OnHandshakeReceived;
154155
testApp.HelpRequested += OnHelpRequested;
155156
testApp.ErrorReceived += _eventHandlers.OnErrorReceived;
156157
testApp.TestProcessExited += _eventHandlers.OnTestProcessExited;

0 commit comments

Comments
 (0)