From dde47f78bda938ad59bd17770ff2a82eaaf580c0 Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Mon, 26 Aug 2024 16:11:16 +0200 Subject: [PATCH 1/3] Send protocol version to the testing platform --- .../commands/dotnet-test/CliConstants.cs | 15 ++++++------- .../commands/dotnet-test/DotnetTestHelper.cs | 10 +++++++++ .../commands/dotnet-test/TestApplication.cs | 21 +++++++++++++++---- .../dotnet-test/TestingPlatformCommand.cs | 8 +++---- 4 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 src/Cli/dotnet/commands/dotnet-test/DotnetTestHelper.cs diff --git a/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs b/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs index 1b1355b164cb..96712d55b69f 100644 --- a/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs +++ b/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs @@ -41,13 +41,14 @@ internal static class SessionEventTypes internal static class HandshakeInfoPropertyNames { - internal const string PID = "PID"; - internal const string Architecture = "Architecture"; - internal const string Framework = "Framework"; - internal const string OS = "OS"; - internal const string ProtocolVersion = "ProtocolVersion"; - internal const string HostType = "HostType"; - internal const string ModulePath = "ModulePath"; + internal const byte PID = 0; + internal const byte Architecture = 1; + internal const byte Framework = 2; + internal const byte OS = 3; + internal const byte SupportedProtocolVersions = 4; + internal const byte HostType = 5; + internal const byte ModulePath = 6; + internal const byte ExecutionId = 7; } internal static class ProtocolConstants diff --git a/src/Cli/dotnet/commands/dotnet-test/DotnetTestHelper.cs b/src/Cli/dotnet/commands/dotnet-test/DotnetTestHelper.cs new file mode 100644 index 000000000000..7ebd8b7c81e1 --- /dev/null +++ b/src/Cli/dotnet/commands/dotnet-test/DotnetTestHelper.cs @@ -0,0 +1,10 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.DotNet.Cli.commands.dotnet_test +{ + internal static class DotnetTestHelper + { + public static string GetSupportedProtocolVersion() => ProtocolConstants.Version; + } +} diff --git a/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs b/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs index a1c12fd8c5ea..cd027987802d 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs @@ -97,7 +97,7 @@ private Task OnRequest(IRequest request) { OnHandshakeInfo(handshakeInfo); - return Task.FromResult((IResponse)CreateHandshakeInfo()); + return Task.FromResult((IResponse)CreateHandshakeInfo(GetSupportedProtocolVersion(handshakeInfo))); } break; @@ -147,14 +147,27 @@ private Task OnRequest(IRequest request) return Task.FromResult((IResponse)VoidResponse.CachedInstance); } - private static HandshakeInfo CreateHandshakeInfo() => - new(new Dictionary + private static string GetSupportedProtocolVersion(HandshakeInfo handshakeInfo) + { + handshakeInfo.Properties.TryGetValue(HandshakeInfoPropertyNames.SupportedProtocolVersions, out string protocolVersions); + string version = string.Empty; + + if (protocolVersions.Split(";").Contains(ProtocolConstants.Version)) + { + version = ProtocolConstants.Version; + } + + return version; + } + + private static HandshakeInfo CreateHandshakeInfo(string version) => + new(new Dictionary { { HandshakeInfoPropertyNames.PID, Process.GetCurrentProcess().Id.ToString() }, { HandshakeInfoPropertyNames.Architecture, RuntimeInformation.OSArchitecture.ToString() }, { HandshakeInfoPropertyNames.Framework, RuntimeInformation.FrameworkDescription }, { HandshakeInfoPropertyNames.OS, RuntimeInformation.OSDescription }, - { HandshakeInfoPropertyNames.ProtocolVersion, ProtocolConstants.Version } + { HandshakeInfoPropertyNames.SupportedProtocolVersions, version } }); private async Task StartProcess(ProcessStartInfo processStartInfo) diff --git a/src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs b/src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs index 46c5c8761e25..a93559bdc8a9 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs @@ -181,14 +181,14 @@ private void OnTestResultReceived(object sender, EventArgs args) { var successfulTestResultMessage = successfulTestResultEventArgs.SuccessfulTestResultMessage; VSTestTrace.SafeWriteTrace(() => $"TestResultMessage: {successfulTestResultMessage.Uid}, {successfulTestResultMessage.DisplayName}, " + - $"{successfulTestResultMessage.State}, {successfulTestResultMessage.Reason}, {successfulTestResultMessage.SessionUid}, {successfulTestResultMessage.ModulePath}"); + $"{successfulTestResultMessage.State}, {successfulTestResultMessage.Reason}, {successfulTestResultMessage.SessionUid}, {successfulTestResultMessage.ExecutionId}"); } else if (args is FailedTestResultEventArgs failedTestResultEventArgs) { var failedTestResultMessage = failedTestResultEventArgs.FailedTestResultMessage; VSTestTrace.SafeWriteTrace(() => $"TestResultMessage: {failedTestResultMessage.Uid}, {failedTestResultMessage.DisplayName}, " + $"{failedTestResultMessage.State}, {failedTestResultMessage.Reason}, {failedTestResultMessage.ErrorMessage}," + - $" {failedTestResultMessage.ErrorStackTrace}, {failedTestResultMessage.SessionUid}, {failedTestResultMessage.ModulePath}"); + $" {failedTestResultMessage.ErrorStackTrace}, {failedTestResultMessage.SessionUid}, {failedTestResultMessage.ExecutionId}"); } } @@ -202,7 +202,7 @@ private void OnFileArtifactInfoReceived(object sender, FileArtifactInfoEventArgs var fileArtifactInfo = args.FileArtifactInfo; VSTestTrace.SafeWriteTrace(() => $"FileArtifactInfo: {fileArtifactInfo.FullPath}, {fileArtifactInfo.DisplayName}, " + $"{fileArtifactInfo.Description}, {fileArtifactInfo.TestUid}, {fileArtifactInfo.TestDisplayName}, " + - $"{fileArtifactInfo.SessionUid}, {fileArtifactInfo.ModulePath}"); + $"{fileArtifactInfo.SessionUid}, {fileArtifactInfo.ExecutionId}"); } private void OnSessionEventReceived(object sender, SessionEventArgs args) @@ -213,7 +213,7 @@ private void OnSessionEventReceived(object sender, SessionEventArgs args) } var sessionEvent = args.SessionEvent; - VSTestTrace.SafeWriteTrace(() => $"TestSessionEvent: {sessionEvent.SessionType}, {sessionEvent.SessionUid}, {sessionEvent.ModulePath}"); + VSTestTrace.SafeWriteTrace(() => $"TestSessionEvent: {sessionEvent.SessionType}, {sessionEvent.SessionUid}, {sessionEvent.ExecutionId}"); } private void OnErrorReceived(object sender, ErrorEventArgs args) From 566a0e79c1602f3ec0157b519fe2e1e389af7955 Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Mon, 26 Aug 2024 17:31:57 +0200 Subject: [PATCH 2/3] add null check --- src/Cli/dotnet/commands/dotnet-test/TestApplication.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs b/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs index 46d78da37b3e..db69c2ae6a44 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs @@ -158,9 +158,9 @@ private Task OnRequest(IRequest request) private static string GetSupportedProtocolVersion(HandshakeInfo handshakeInfo) { handshakeInfo.Properties.TryGetValue(HandshakeInfoPropertyNames.SupportedProtocolVersions, out string protocolVersions); - string version = string.Empty; - if (protocolVersions.Split(";").Contains(ProtocolConstants.Version)) + string version = string.Empty; + if (protocolVersions is not null && protocolVersions.Split(";").Contains(ProtocolConstants.Version)) { version = ProtocolConstants.Version; } From de36a701129de7ca1549c454d3bc105700f91afe Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Mon, 26 Aug 2024 17:34:07 +0200 Subject: [PATCH 3/3] remove unused class --- .../dotnet/commands/dotnet-test/DotnetTestHelper.cs | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 src/Cli/dotnet/commands/dotnet-test/DotnetTestHelper.cs diff --git a/src/Cli/dotnet/commands/dotnet-test/DotnetTestHelper.cs b/src/Cli/dotnet/commands/dotnet-test/DotnetTestHelper.cs deleted file mode 100644 index 7ebd8b7c81e1..000000000000 --- a/src/Cli/dotnet/commands/dotnet-test/DotnetTestHelper.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.DotNet.Cli.commands.dotnet_test -{ - internal static class DotnetTestHelper - { - public static string GetSupportedProtocolVersion() => ProtocolConstants.Version; - } -}