From 433471a6d37285f53915aba352740606d05caf27 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Mon, 31 Jan 2022 19:08:28 +0100 Subject: [PATCH 01/12] Map incoming and outgoing requests --- playground/TestPlatform.Playground/Program.cs | 36 ++- .../Properties/launchSettings.json | 3 +- .../TestPlatform.Playground.csproj | 4 +- .../EventHandlers/TestRequestHandler.cs | 269 +++++++++++++++++- .../Hosting/DefaultTestHostManager.cs | 55 ++++ src/testhost.x86/DefaultEngineInvoker.cs | 13 + 6 files changed, 363 insertions(+), 17 deletions(-) diff --git a/playground/TestPlatform.Playground/Program.cs b/playground/TestPlatform.Playground/Program.cs index edd8b95e21..a806ce620b 100644 --- a/playground/TestPlatform.Playground/Program.cs +++ b/playground/TestPlatform.Playground/Program.cs @@ -57,7 +57,9 @@ static void Main(string[] args) }; var options = new TestPlatformOptions(); - r.RunTestsWithCustomTestHost(sources, sourceSettings, options, new TestRunHandler(), new DebuggerTestHostLauncher()); + var discoveryHandler = new TestDiscoveryHandler(); + r.DiscoverTests(sources, sourceSettings, options, discoveryHandler); + r.RunTestsWithCustomTestHost(discoveryHandler.DiscoveredTestCases, sourceSettings, options, new TestRunHandler(), new DebuggerTestHostLauncher()); } public class TestRunHandler : ITestRunEventsHandler @@ -103,6 +105,38 @@ private string WriteTests(IEnumerable testCases) } } + public class TestDiscoveryHandler : ITestDiscoveryEventsHandler2 + { + public List DiscoveredTestCases { get; } = new List(); + public List Messages { get; } = new List(); + + public void HandleDiscoveredTests(IEnumerable discoveredTestCases) + { + if (discoveredTestCases != null) + { + DiscoveredTestCases.AddRange(discoveredTestCases); + } + } + + public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable lastChunk) + { + if (lastChunk != null) + { + DiscoveredTestCases.AddRange(lastChunk); + } + } + + public void HandleLogMessage(TestMessageLevel level, string message) + { + Messages.Add($"[{level}]: {message}"); + } + + public void HandleRawMessage(string rawMessage) + { + + } + } + internal class DebuggerTestHostLauncher : ITestHostLauncher2 { public bool IsDebug => true; diff --git a/playground/TestPlatform.Playground/Properties/launchSettings.json b/playground/TestPlatform.Playground/Properties/launchSettings.json index c8493b971d..3fcb76c5af 100644 --- a/playground/TestPlatform.Playground/Properties/launchSettings.json +++ b/playground/TestPlatform.Playground/Properties/launchSettings.json @@ -3,6 +3,7 @@ "TestPlatform.Playground": { "commandName": "Project", "environmentVariables": { + "VSTEST_CONNECTION_TIMEOUT": "999", "VSTEST_RUNNER_DEBUG_ATTACHVS": "1", "VSTEST_DEBUG_NOBP": "1", "VSTEST_HOST_DEBUG_ATTACHVS": "1", @@ -10,4 +11,4 @@ } } } -} \ No newline at end of file +} diff --git a/playground/TestPlatform.Playground/TestPlatform.Playground.csproj b/playground/TestPlatform.Playground/TestPlatform.Playground.csproj index 4fbfd04487..90344ce679 100644 --- a/playground/TestPlatform.Playground/TestPlatform.Playground.csproj +++ b/playground/TestPlatform.Playground/TestPlatform.Playground.csproj @@ -1,4 +1,4 @@ - + ..\..\ true @@ -36,7 +36,7 @@ - + diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs index 2d2f2b2e71..cc6dcecbce 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs @@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using EventHandlers; @@ -21,6 +22,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using CrossPlatResources = CrossPlatEngine.Resources.Resources; using ObjectModelConstants = TestPlatform.ObjectModel.Constants; +using System.Collections.ObjectModel; public class TestRequestHandler : ITestRequestHandler { @@ -42,6 +44,7 @@ public class TestRequestHandler : ITestRequestHandler private readonly ManualResetEventSlim _sessionCompleted; private Action _onLaunchAdapterProcessWithDebuggerAttachedAckReceived; private Action _onAttachDebuggerAckRecieved; + private IPathConverter _pathConverter; private Exception _messageProcessingUnrecoverableError; public TestHostConnectionInfo ConnectionInfo { get; set; } @@ -82,6 +85,7 @@ protected TestRequestHandler(IDataSerializer dataSerializer, ICommunicationEndpo _onLaunchAdapterProcessWithDebuggerAttachedAckReceived = (message) => throw new NotImplementedException(); _onAttachDebuggerAckRecieved = (message) => throw new NotImplementedException(); + _pathConverter = new NullPathConverter(); _jobQueue = new JobQueue( (action) => action(), "TestHostOperationQueue", @@ -94,6 +98,19 @@ protected TestRequestHandler(IDataSerializer dataSerializer, ICommunicationEndpo /// public virtual void InitializeCommunication() { + // soo beautiful! + var localPath = Environment.GetEnvironmentVariable("--local-path"); + var remotePath = Environment.GetEnvironmentVariable("--remote-path"); + + if (!string.IsNullOrWhiteSpace(localPath) && !string.IsNullOrEmpty(remotePath)) + { + _pathConverter = new PathConverter(localPath, remotePath); + } + else + { + _pathConverter = new NullPathConverter(); + } + _communicationEndPoint = _communicationEndpointFactory.Create(ConnectionInfo.Role); _communicationEndPoint.Connected += (sender, connectedArgs) => { @@ -141,14 +158,16 @@ public void Close() /// public void SendTestCases(IEnumerable discoveredTestCases) { - var data = _dataSerializer.SerializePayload(MessageType.TestCasesFound, discoveredTestCases, _protocolVersion); + var updatedTestCases = _pathConverter.UpdateTestCases(discoveredTestCases, Direction.Send); + var data = _dataSerializer.SerializePayload(MessageType.TestCasesFound, updatedTestCases, _protocolVersion); SendData(data); } /// public void SendTestRunStatistics(TestRunChangedEventArgs testRunChangedArgs) { - var data = _dataSerializer.SerializePayload(MessageType.TestRunStatsChange, testRunChangedArgs, _protocolVersion); + var updatedTestRunChangedEventArgs = _pathConverter.UpdateTestRunChangedEventArgs(testRunChangedArgs, Direction.Send); + var data = _dataSerializer.SerializePayload(MessageType.TestRunStatsChange, updatedTestRunChangedEventArgs, _protocolVersion); SendData(data); } @@ -179,16 +198,16 @@ public void SendExecutionComplete( curentArgs.IsCanceled, curentArgs.IsAborted, _messageProcessingUnrecoverableError, - curentArgs.AttachmentSets, curentArgs.InvokedDataCollectors, curentArgs.ElapsedTimeInRunningTests + _pathConverter.UpdateAttachmentSets(curentArgs.AttachmentSets, Direction.Send), curentArgs.InvokedDataCollectors, curentArgs.ElapsedTimeInRunningTests ); } var data = _dataSerializer.SerializePayload( MessageType.ExecutionComplete, new TestRunCompletePayload { - TestRunCompleteArgs = testRunCompleteArgs, - LastRunTests = lastChunkArgs, - RunAttachments = runContextAttachments, + TestRunCompleteArgs = _pathConverter.UpdateTestRunCompleteEventArgs(testRunCompleteArgs, Direction.Send), + LastRunTests = _pathConverter.UpdateTestRunChangedEventArgs(lastChunkArgs, Direction.Send), + RunAttachments = _pathConverter.UpdateAttachmentSets(runContextAttachments, Direction.Send), ExecutorUris = executorUris }, _protocolVersion); @@ -203,7 +222,7 @@ public void DiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventA new DiscoveryCompletePayload { TotalTests = discoveryCompleteEventArgs.TotalCount, - LastDiscoveredTests = discoveryCompleteEventArgs.IsAborted ? null : lastChunk, + LastDiscoveredTests = discoveryCompleteEventArgs.IsAborted ? null : _pathConverter.UpdateTestCases(lastChunk, Direction.Send), IsAborted = discoveryCompleteEventArgs.IsAborted, Metrics = discoveryCompleteEventArgs.Metrics }, @@ -333,7 +352,7 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec { _testHostManagerFactoryReady.Wait(); var discoveryEventsHandler = new TestDiscoveryEventHandler(this); - var pathToAdditionalExtensions = _dataSerializer.DeserializePayload>(message); + var pathToAdditionalExtensions = _pathConverter.UpdatePaths(_dataSerializer.DeserializePayload>(message), Direction.Receive); Action job = () => { EqtTrace.Info("TestRequestHandler.OnMessageReceived: Running job '{0}'.", message.MessageType); @@ -357,7 +376,8 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec { _testHostManagerFactoryReady.Wait(); var discoveryEventsHandler = new TestDiscoveryEventHandler(this); - var discoveryCriteria = _dataSerializer.DeserializePayload(message); + var discoveryCriteria = _pathConverter.UpdateDiscoveryCriteria(_dataSerializer.DeserializePayload(message), Direction.Receive); + Action job = () => { EqtTrace.Info("TestRequestHandler.OnMessageReceived: Running job '{0}'.", message.MessageType); @@ -383,7 +403,7 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec { _testHostManagerFactoryReady.Wait(); var testInitializeEventsHandler = new TestInitializeEventsHandler(this); - var pathToAdditionalExtensions = _dataSerializer.DeserializePayload>(message); + var pathToAdditionalExtensions = _pathConverter.UpdatePaths(_dataSerializer.DeserializePayload>(message), Direction.Receive); Action job = () => { EqtTrace.Info("TestRequestHandler.OnMessageReceived: Running job '{0}'.", message.MessageType); @@ -407,7 +427,7 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec { var testRunEventsHandler = new TestRunEventsHandler(this); _testHostManagerFactoryReady.Wait(); - var testRunCriteriaWithSources = _dataSerializer.DeserializePayload(message); + var testRunCriteriaWithSources = _pathConverter.UpdateTestRunCriteriaWithSources(_dataSerializer.DeserializePayload(message), Direction.Receive); Action job = () => { EqtTrace.Info("TestRequestHandler.OnMessageReceived: Running job '{0}'.", message.MessageType); @@ -438,8 +458,7 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec { var testRunEventsHandler = new TestRunEventsHandler(this); _testHostManagerFactoryReady.Wait(); - var testRunCriteriaWithTests = - _dataSerializer.DeserializePayload(message); + var testRunCriteriaWithTests = _pathConverter.UpdateTestRunCriteriaWithTests(_dataSerializer.DeserializePayload(message), Direction.Receive); Action job = () => { @@ -535,4 +554,228 @@ private void SendData(string data) EqtTrace.Verbose("TestRequestHandler.SendData: sending data from testhost: {0}", data); _channel.Send(data); } +} + +internal class NullPathConverter : IPathConverter +{ + Collection IPathConverter.UpdateAttachmentSets(Collection attachmentSets, Direction updateDirection) + { + return attachmentSets; + } + + ICollection IPathConverter.UpdateAttachmentSets(ICollection attachmentSets, Direction updateDirection) + { + return attachmentSets; + } + + DiscoveryCriteria IPathConverter.UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, Direction updateDirection) + { + return discoveryCriteria; + } + + string IPathConverter.UpdatePath(string path, Direction updateDirection) + { + return path; + } + + IEnumerable IPathConverter.UpdatePaths(IEnumerable enumerable, Direction updateDirection) + { + return enumerable; + } + + TestCase IPathConverter.UpdateTestCase(TestCase testCase, Direction updateDirection) + { + return testCase; + } + + IEnumerable IPathConverter.UpdateTestCases(IEnumerable testCases, Direction updateDirection) + { + return testCases; + } + + TestRunChangedEventArgs IPathConverter.UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, Direction updateDirection) + { + return testRunChangedArgs; + } + + TestRunCompleteEventArgs IPathConverter.UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, Direction updateDirection) + { + return testRunCompleteEventArgs; + } + + TestRunCriteriaWithSources IPathConverter.UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, Direction updateDirection) + { + return testRunCriteriaWithSources; + } + + TestRunCriteriaWithTests IPathConverter.UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, Direction updateDirection) + { + return testRunCriteriaWithTests; + } +} + +internal enum Direction +{ + Receive, + Send +} + +internal class PathConverter : IPathConverter +{ + // The path on this computer to which we deployed the test dll and test runner + private readonly string _deploymentPath = ""; + // The path on the remote system where test dll was originally placed, and from which we + // copied it to this system. For vstest.console, which is on the other side of this, the names + // are inverted, it sends us their local path, and thinks about our local path as remote. + private readonly string _originalPath = ""; + + public PathConverter(string originalPath, string deploymentPath) + { + _originalPath = originalPath; + _deploymentPath = deploymentPath; + } + + public string UpdatePath(string path, Direction updateDirection) + { + string find; + string replaceWith; + if (updateDirection == Direction.Receive) + { + // Request is incoming, the path that is local to the sender (for us that is "remote" path) + // needs to be replaced with our path + find = _originalPath; + replaceWith = _deploymentPath; + } + else + { + find = _deploymentPath; + replaceWith = _originalPath; + } + + return path?.Replace(find, replaceWith); + } + + public IEnumerable UpdatePaths(IEnumerable enumerable, Direction updateDirection) + { + var updatedPaths = enumerable.Select(i => UpdatePath(i, updateDirection)).ToList(); + return updatedPaths; + } + + public TestCase UpdateTestCase(TestCase testCase, Direction updateDirection) + { + testCase.CodeFilePath = UpdatePath(testCase.CodeFilePath, updateDirection); + testCase.Source = UpdatePath(testCase.Source, updateDirection); + return testCase; + } + + public IEnumerable UpdateTestCases(IEnumerable testCases, Direction updateDirection) + { + var updatedTestCases = testCases.Select(tc => UpdateTestCase(tc, updateDirection)).ToList(); + + return updatedTestCases; + } + + public TestRunCompleteEventArgs UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, Direction updateDirection) + { + UpdateAttachmentSets(testRunCompleteEventArgs.AttachmentSets, updateDirection); + return testRunCompleteEventArgs; + } + + public TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, Direction updateDirection) + { + UpdateTestResults(testRunChangedArgs.NewTestResults, updateDirection); + UpdateTestCases(testRunChangedArgs.ActiveTests, updateDirection); + return testRunChangedArgs; + } + + public Collection UpdateAttachmentSets(Collection attachmentSets, Direction updateDirection) + { + attachmentSets.Select(i => UpdateAttachmentSet(i, updateDirection)); + return attachmentSets; + } + + public ICollection UpdateAttachmentSets(ICollection attachmentSets, Direction updateDirection) + { + attachmentSets.Select(i => UpdateAttachmentSet(i, updateDirection)); + return attachmentSets; + } + + private AttachmentSet UpdateAttachmentSet(AttachmentSet attachmentSet, Direction updateDirection) + { + attachmentSet.Attachments.Select(a => UpdateAttachment(a, updateDirection)); + return attachmentSet; + } + + private UriDataAttachment UpdateAttachment(UriDataAttachment attachment, Direction updateDirection) + { + // todo: convert uri? + return attachment; + } + + private IEnumerable UpdateTestResults(IEnumerable testResults, Direction updateDirection) + { + testResults.Select(tr => + { + tr.Attachments.Select(a => UpdateAttachmentSet(a, updateDirection)); + UpdateTestCase(tr.TestCase, updateDirection); + + return tr; + }); + + return testResults; + } + + public DiscoveryCriteria UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, Direction updateDirection) + { + discoveryCriteria.Package = UpdatePath(discoveryCriteria.Package, updateDirection); + foreach (var adapter in discoveryCriteria.AdapterSourceMap.ToList()) + { + var updatedPaths = UpdatePaths(adapter.Value, updateDirection); + discoveryCriteria.AdapterSourceMap[adapter.Key] = updatedPaths; + } + return discoveryCriteria; + } + + public TestRunCriteriaWithSources UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, Direction updateDirection) + { + testRunCriteriaWithSources.AdapterSourceMap.Select(adapter => testRunCriteriaWithSources.AdapterSourceMap[adapter.Key] = UpdatePaths(adapter.Value, updateDirection)); + var package = UpdatePath(testRunCriteriaWithSources.Package, updateDirection); + return new TestRunCriteriaWithSources(testRunCriteriaWithSources.AdapterSourceMap, package, testRunCriteriaWithSources.RunSettings, testRunCriteriaWithSources.TestExecutionContext); + } + + public TestRunCriteriaWithTests UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, Direction updateDirection) + { + var tests = UpdateTestCases(testRunCriteriaWithTests.Tests, updateDirection); + var package = UpdatePath(testRunCriteriaWithTests.Package, updateDirection); + return new TestRunCriteriaWithTests(tests, package, testRunCriteriaWithTests.RunSettings, testRunCriteriaWithTests.TestExecutionContext); + } +} + +internal interface IPathConverter +{ + internal string UpdatePath(string path, Direction updateDirection); + + + internal IEnumerable UpdatePaths(IEnumerable enumerable, Direction updateDirection); + + internal TestCase UpdateTestCase(TestCase testCase, Direction updateDirection); + + internal IEnumerable UpdateTestCases(IEnumerable testCases, Direction updateDirection); + + + internal TestRunCompleteEventArgs UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, Direction updateDirection); + + + internal TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, Direction updateDirection); + + + internal Collection UpdateAttachmentSets(Collection attachmentSets, Direction updateDirection); + + internal ICollection UpdateAttachmentSets(ICollection attachmentSets, Direction updateDirection); + + internal DiscoveryCriteria UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, Direction updateDirection); + + internal TestRunCriteriaWithSources UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, Direction updateDirection); + + internal TestRunCriteriaWithTests UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, Direction updateDirection); } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index 233f2020bf..f97c443c7d 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -163,6 +163,8 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( testhostProcessPath = Path.Combine(currentWorkingDirectory, testHostProcessName); } + + if (!Shared) { // Not sharing the host which means we need to pass the test assembly path as argument @@ -170,6 +172,31 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( argumentsString += " --testsourcepath " + sources.FirstOrDefault().AddDoubleQuote(); } + // do something like deploy, we copy the whole folder, and remote the sources + // from the original folder + var localDirectory = Path.GetDirectoryName(sources.FirstOrDefault()); + var remoteDirectory = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(sources.FirstOrDefault()), "..", "remote")); + + + // delete only if sources exist, we will delete the test.dll few lines below to make + // sure we are not using just the one from the original path, instead from the deploy + // path, but because we start new testhost after discovery, we would be deleting the + // only copy of tests.dll, and copying the original folder without it. + if (sources.All(File.Exists) && Directory.Exists(remoteDirectory)) + { + Directory.Delete(remoteDirectory, true); + } + Copy(localDirectory, remoteDirectory); + sources.ToList().ForEach(File.Delete); + // deploy end + + + // this is the path where we deployed the files + argumentsString += " --remote-path " + remoteDirectory; + + // this is the path where the files were originally + argumentsString += " --local-path " + localDirectory; + EqtTrace.Verbose("DefaultTestHostmanager: Full path of {0} is {1}", testHostProcessName, testhostProcessPath); var launcherPath = testhostProcessPath; @@ -193,6 +220,34 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( EnvironmentVariables = environmentVariables ?? new Dictionary(), WorkingDirectory = processWorkingDirectory }; + + void Copy(string sourceDirectory, string targetDirectory) + { + var diSource = new DirectoryInfo(sourceDirectory); + var diTarget = new DirectoryInfo(targetDirectory); + + CopyAll(diSource, diTarget); + } + + void CopyAll(DirectoryInfo source, DirectoryInfo target) + { + Directory.CreateDirectory(target.FullName); + + // Copy each file into the new directory. + foreach (FileInfo fi in source.GetFiles()) + { + Console.WriteLine(@"Copying {0}\{1}", target.FullName, fi.Name); + fi.CopyTo(Path.Combine(target.FullName, fi.Name), true); + } + + // Copy each subdirectory using recursion. + foreach (DirectoryInfo diSourceSubDir in source.GetDirectories()) + { + DirectoryInfo nextTargetSubDir = + target.CreateSubdirectory(diSourceSubDir.Name); + CopyAll(diSourceSubDir, nextTargetSubDir); + } + } } /// diff --git a/src/testhost.x86/DefaultEngineInvoker.cs b/src/testhost.x86/DefaultEngineInvoker.cs index 6a92b2a6d8..9dbd7588d4 100644 --- a/src/testhost.x86/DefaultEngineInvoker.cs +++ b/src/testhost.x86/DefaultEngineInvoker.cs @@ -59,6 +59,13 @@ internal class DefaultEngineInvoker : private const string TelemetryOptedIn = "--telemetryoptedin"; + // this path is where the sources were originally located on the source system + // we are in a testhost that runs on the remote system, so this local path is + // actually remote for us and the remote path is local for us. + private const string LocalPath = "--local-path"; + + private const string RemotePath = "--remote-path"; + private readonly ITestRequestHandler _requestHandler; private readonly IDataCollectionTestCaseEventSender _dataCollectionTestCaseEventSender; @@ -81,6 +88,12 @@ public void Invoke(IDictionary argsDictionary) { InitializeEqtTrace(argsDictionary); + if (argsDictionary.ContainsKey(RemotePath) && argsDictionary.ContainsKey(LocalPath)) + { + Environment.SetEnvironmentVariable(LocalPath, argsDictionary[LocalPath]); + Environment.SetEnvironmentVariable(RemotePath, argsDictionary[RemotePath]); + } + if (EqtTrace.IsVerboseEnabled) { var version = typeof(DefaultEngineInvoker) From b7a547add37bc8a35ad55d70008e0301441b0c06 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Tue, 1 Feb 2022 15:05:47 +0100 Subject: [PATCH 02/12] Fix deployment to not copy twice --- playground/TestPlatform.Playground/Program.cs | 16 ++++++++++++++++ .../Properties/launchSettings.json | 2 +- .../Hosting/DefaultTestHostManager.cs | 14 +++++++++----- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/playground/TestPlatform.Playground/Program.cs b/playground/TestPlatform.Playground/Program.cs index a806ce620b..5c0c710f07 100644 --- a/playground/TestPlatform.Playground/Program.cs +++ b/playground/TestPlatform.Playground/Program.cs @@ -59,6 +59,9 @@ static void Main(string[] args) var options = new TestPlatformOptions(); var discoveryHandler = new TestDiscoveryHandler(); r.DiscoverTests(sources, sourceSettings, options, discoveryHandler); + if (File.Exists(sources[0])) { + throw new Exception($"File {sources[0]} exists, but it should not because we moved it during deployment!"); + } r.RunTestsWithCustomTestHost(discoveryHandler.DiscoveredTestCases, sourceSettings, options, new TestRunHandler(), new DebuggerTestHostLauncher()); } @@ -115,6 +118,7 @@ public void HandleDiscoveredTests(IEnumerable discoveredTestCases) if (discoveredTestCases != null) { DiscoveredTestCases.AddRange(discoveredTestCases); + Console.WriteLine($"[DISCOVERY UPDATE] {WriteTests(discoveredTestCases)}"); } } @@ -123,17 +127,29 @@ public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryComplete if (lastChunk != null) { DiscoveredTestCases.AddRange(lastChunk); + Console.WriteLine($"[DISCOVERY COMPLETE] {WriteTests(lastChunk)}"); } } public void HandleLogMessage(TestMessageLevel level, string message) { Messages.Add($"[{level}]: {message}"); + Console.WriteLine(($"[{level}]: {message}")); } public void HandleRawMessage(string rawMessage) { + Console.WriteLine(($"[RAWMESSAGE]: {rawMessage}")); + } + + private string WriteTests(IEnumerable testResults) + { + return WriteTests(testResults?.Select(t => t.TestCase)); + } + private string WriteTests(IEnumerable testCases) + { + return testCases == null ? null : "\t" + string.Join("\n\t", testCases.Select(r => r.DisplayName)); } } diff --git a/playground/TestPlatform.Playground/Properties/launchSettings.json b/playground/TestPlatform.Playground/Properties/launchSettings.json index 3fcb76c5af..c688670d9c 100644 --- a/playground/TestPlatform.Playground/Properties/launchSettings.json +++ b/playground/TestPlatform.Playground/Properties/launchSettings.json @@ -4,8 +4,8 @@ "commandName": "Project", "environmentVariables": { "VSTEST_CONNECTION_TIMEOUT": "999", - "VSTEST_RUNNER_DEBUG_ATTACHVS": "1", "VSTEST_DEBUG_NOBP": "1", + "VSTEST_RUNNER_DEBUG_ATTACHVS": "1", "VSTEST_HOST_DEBUG_ATTACHVS": "1", "VSTEST_DATACOLLECTOR_DEBUG_ATTACHVS": "1" } diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index f97c443c7d..026af43861 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -178,16 +178,20 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( var remoteDirectory = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(sources.FirstOrDefault()), "..", "remote")); - // delete only if sources exist, we will delete the test.dll few lines below to make + // delete and copy only if sources exist, we will delete the test.dll few lines below to make // sure we are not using just the one from the original path, instead from the deploy // path, but because we start new testhost after discovery, we would be deleting the // only copy of tests.dll, and copying the original folder without it. - if (sources.All(File.Exists) && Directory.Exists(remoteDirectory)) + if (sources.All(File.Exists)) { - Directory.Delete(remoteDirectory, true); + if (Directory.Exists(remoteDirectory)) + { + Directory.Delete(remoteDirectory, true); + } + + Copy(localDirectory, remoteDirectory); + sources.ToList().ForEach(File.Delete); } - Copy(localDirectory, remoteDirectory); - sources.ToList().ForEach(File.Delete); // deploy end From 084f781d395c1bab637ea574e62e90a0937752e3 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Mon, 14 Feb 2022 13:38:13 +0100 Subject: [PATCH 03/12] Fix path passing --- .../EventHandlers/TestRequestHandler.cs | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs index cc6dcecbce..dcb20bc1be 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs @@ -23,6 +23,9 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using CrossPlatResources = CrossPlatEngine.Resources.Resources; using ObjectModelConstants = TestPlatform.ObjectModel.Constants; using System.Collections.ObjectModel; +using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; +using System.IO; +using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; public class TestRequestHandler : ITestRequestHandler { @@ -39,6 +42,7 @@ public class TestRequestHandler : ITestRequestHandler private ICommunicationChannel _channel; private readonly JobQueue _jobQueue; + private readonly IFileHelper _fileHelper; private readonly ManualResetEventSlim _requestSenderConnected; private readonly ManualResetEventSlim _testHostManagerFactoryReady; private readonly ManualResetEventSlim _sessionCompleted; @@ -73,6 +77,7 @@ protected TestRequestHandler( _onLaunchAdapterProcessWithDebuggerAttachedAckReceived = onLaunchAdapterProcessWithDebuggerAttachedAckReceived; _onAttachDebuggerAckRecieved = onAttachDebuggerAckRecieved; _jobQueue = jobQueue; + _fileHelper = new FileHelper(); } protected TestRequestHandler(IDataSerializer dataSerializer, ICommunicationEndpointFactory communicationEndpointFactory) @@ -93,6 +98,7 @@ protected TestRequestHandler(IDataSerializer dataSerializer, ICommunicationEndpo 25000000, true, (message) => EqtTrace.Error(message)); + _fileHelper = new FileHelper(); } /// @@ -104,7 +110,7 @@ public virtual void InitializeCommunication() if (!string.IsNullOrWhiteSpace(localPath) && !string.IsNullOrEmpty(remotePath)) { - _pathConverter = new PathConverter(localPath, remotePath); + _pathConverter = new PathConverter(localPath, remotePath, _fileHelper); } else { @@ -629,10 +635,10 @@ internal class PathConverter : IPathConverter // are inverted, it sends us their local path, and thinks about our local path as remote. private readonly string _originalPath = ""; - public PathConverter(string originalPath, string deploymentPath) + public PathConverter(string originalPath, string deploymentPath, IFileHelper fileHelper) { - _originalPath = originalPath; - _deploymentPath = deploymentPath; + _originalPath = fileHelper.GetFullPath(originalPath).TrimEnd('\\').TrimEnd('/') + Path.DirectorySeparatorChar; + _deploymentPath = fileHelper.GetFullPath(deploymentPath).TrimEnd('\\').TrimEnd('/') + Path.DirectorySeparatorChar; } public string UpdatePath(string path, Direction updateDirection) @@ -652,7 +658,8 @@ public string UpdatePath(string path, Direction updateDirection) replaceWith = _originalPath; } - return path?.Replace(find, replaceWith); + var result = path?.Replace(find, replaceWith); + return result; } public IEnumerable UpdatePaths(IEnumerable enumerable, Direction updateDirection) @@ -690,19 +697,19 @@ public TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEvent public Collection UpdateAttachmentSets(Collection attachmentSets, Direction updateDirection) { - attachmentSets.Select(i => UpdateAttachmentSet(i, updateDirection)); + attachmentSets.Select(i => UpdateAttachmentSet(i, updateDirection)).ToList(); return attachmentSets; } public ICollection UpdateAttachmentSets(ICollection attachmentSets, Direction updateDirection) { - attachmentSets.Select(i => UpdateAttachmentSet(i, updateDirection)); + attachmentSets.Select(i => UpdateAttachmentSet(i, updateDirection)).ToList(); return attachmentSets; } private AttachmentSet UpdateAttachmentSet(AttachmentSet attachmentSet, Direction updateDirection) { - attachmentSet.Attachments.Select(a => UpdateAttachment(a, updateDirection)); + attachmentSet.Attachments.Select(a => UpdateAttachment(a, updateDirection)).ToList(); return attachmentSet; } @@ -714,13 +721,14 @@ private UriDataAttachment UpdateAttachment(UriDataAttachment attachment, Directi private IEnumerable UpdateTestResults(IEnumerable testResults, Direction updateDirection) { - testResults.Select(tr => + // The incoming collection is IEnumerable, use foreach to make sure we always do the changes, + // as opposed to using .Select which will never run unless you ask for results (which totally + // did not happen to me, of course). + foreach (var tr in testResults) { tr.Attachments.Select(a => UpdateAttachmentSet(a, updateDirection)); UpdateTestCase(tr.TestCase, updateDirection); - - return tr; - }); + } return testResults; } From 2e1f8a534bb31cc7f9b25c62497d94b54021202b Mon Sep 17 00:00:00 2001 From: nohwnd Date: Mon, 14 Feb 2022 16:40:24 +0100 Subject: [PATCH 04/12] Cleanup --- playground/TestPlatform.Playground/Program.cs | 3 +- .../IDeploymentAwareTestRequestHandler.cs | 15 + .../EventHandlers/IPathConverter.cs | 38 +++ .../EventHandlers/NullPathConverter.cs | 67 +++++ .../EventHandlers/PathConversionDirection.cs | 10 + .../EventHandlers/PathConverter.cs | 145 ++++++++++ .../EventHandlers/TestRequestHandler.cs | 267 ++---------------- .../Friends.cs | 17 ++ src/testhost.x86/DefaultEngineInvoker.cs | 11 +- 9 files changed, 321 insertions(+), 252 deletions(-) create mode 100644 src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IDeploymentAwareTestRequestHandler.cs create mode 100644 src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs create mode 100644 src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs create mode 100644 src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConversionDirection.cs create mode 100644 src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs diff --git a/playground/TestPlatform.Playground/Program.cs b/playground/TestPlatform.Playground/Program.cs index 5c0c710f07..8454c14a4d 100644 --- a/playground/TestPlatform.Playground/Program.cs +++ b/playground/TestPlatform.Playground/Program.cs @@ -59,7 +59,8 @@ static void Main(string[] args) var options = new TestPlatformOptions(); var discoveryHandler = new TestDiscoveryHandler(); r.DiscoverTests(sources, sourceSettings, options, discoveryHandler); - if (File.Exists(sources[0])) { + if (File.Exists(sources[0])) + { throw new Exception($"File {sources[0]} exists, but it should not because we moved it during deployment!"); } r.RunTestsWithCustomTestHost(discoveryHandler.DiscoveredTestCases, sourceSettings, options, new TestRunHandler(), new DebuggerTestHostLauncher()); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IDeploymentAwareTestRequestHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IDeploymentAwareTestRequestHandler.cs new file mode 100644 index 0000000000..fce03ff6ff --- /dev/null +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IDeploymentAwareTestRequestHandler.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; + +/// +/// This interface holds additional values for a request handler when rewriting paths is used. +/// This is in case when --local-path and --remote-path parameters are provided and testhost is running +/// in a remote deployment. This interface is used only to avoid changes to public API of TestRequestHandler. +/// +internal interface IDeploymentAwareTestRequestHandler +{ + string LocalPath { get; set; } + string RemotePath { get; set; } +} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs new file mode 100644 index 0000000000..62ab4129c7 --- /dev/null +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; +using System.Collections.Generic; +using ObjectModel; +using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; +using System.Collections.ObjectModel; + +internal interface IPathConverter +{ + internal string UpdatePath(string path, PathConversionDirection updateDirection); + + + internal IEnumerable UpdatePaths(IEnumerable enumerable, PathConversionDirection updateDirection); + + internal TestCase UpdateTestCase(TestCase testCase, PathConversionDirection updateDirection); + + internal IEnumerable UpdateTestCases(IEnumerable testCases, PathConversionDirection updateDirection); + + + internal TestRunCompleteEventArgs UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, PathConversionDirection updateDirection); + + + internal TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, PathConversionDirection updateDirection); + + + internal Collection UpdateAttachmentSets(Collection attachmentSets, PathConversionDirection updateDirection); + + internal ICollection UpdateAttachmentSets(ICollection attachmentSets, PathConversionDirection updateDirection); + + internal DiscoveryCriteria UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, PathConversionDirection updateDirection); + + internal TestRunCriteriaWithSources UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, PathConversionDirection updateDirection); + + internal TestRunCriteriaWithTests UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, PathConversionDirection updateDirection); +} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs new file mode 100644 index 0000000000..5a1ef33aef --- /dev/null +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; +using System.Collections.Generic; +using ObjectModel; +using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; +using System.Collections.ObjectModel; + +internal class NullPathConverter : IPathConverter +{ + Collection IPathConverter.UpdateAttachmentSets(Collection attachmentSets, PathConversionDirection updateDirection) + { + return attachmentSets; + } + + ICollection IPathConverter.UpdateAttachmentSets(ICollection attachmentSets, PathConversionDirection updateDirection) + { + return attachmentSets; + } + + DiscoveryCriteria IPathConverter.UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, PathConversionDirection updateDirection) + { + return discoveryCriteria; + } + + string IPathConverter.UpdatePath(string path, PathConversionDirection updateDirection) + { + return path; + } + + IEnumerable IPathConverter.UpdatePaths(IEnumerable enumerable, PathConversionDirection updateDirection) + { + return enumerable; + } + + TestCase IPathConverter.UpdateTestCase(TestCase testCase, PathConversionDirection updateDirection) + { + return testCase; + } + + IEnumerable IPathConverter.UpdateTestCases(IEnumerable testCases, PathConversionDirection updateDirection) + { + return testCases; + } + + TestRunChangedEventArgs IPathConverter.UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, PathConversionDirection updateDirection) + { + return testRunChangedArgs; + } + + TestRunCompleteEventArgs IPathConverter.UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, PathConversionDirection updateDirection) + { + return testRunCompleteEventArgs; + } + + TestRunCriteriaWithSources IPathConverter.UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, PathConversionDirection updateDirection) + { + return testRunCriteriaWithSources; + } + + TestRunCriteriaWithTests IPathConverter.UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, PathConversionDirection updateDirection) + { + return testRunCriteriaWithTests; + } +} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConversionDirection.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConversionDirection.cs new file mode 100644 index 0000000000..a8c6591ac6 --- /dev/null +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConversionDirection.cs @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; + +internal enum PathConversionDirection +{ + Receive, + Send +} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs new file mode 100644 index 0000000000..14d0f6ccf6 --- /dev/null +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs @@ -0,0 +1,145 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; +using System.Collections.Generic; +using System.Linq; +using ObjectModel; +using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; +using System.Collections.ObjectModel; +using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; +using System.IO; + +internal class PathConverter : IPathConverter +{ + // The path on this computer to which we deployed the test dll and test runner + private readonly string _deploymentPath = ""; + // The path on the remote system where test dll was originally placed, and from which we + // copied it to this system. For vstest.console, which is on the other side of this, the names + // are inverted, it sends us their local path, and thinks about our local path as remote. + private readonly string _originalPath = ""; + + public PathConverter(string originalPath, string deploymentPath, IFileHelper fileHelper) + { + _originalPath = fileHelper.GetFullPath(originalPath).TrimEnd('\\').TrimEnd('/') + Path.DirectorySeparatorChar; + _deploymentPath = fileHelper.GetFullPath(deploymentPath).TrimEnd('\\').TrimEnd('/') + Path.DirectorySeparatorChar; + } + + public string UpdatePath(string path, PathConversionDirection updateDirection) + { + string find; + string replaceWith; + if (updateDirection == PathConversionDirection.Receive) + { + // Request is incoming, the path that is local to the sender (for us that is "remote" path) + // needs to be replaced with our path + find = _originalPath; + replaceWith = _deploymentPath; + } + else + { + find = _deploymentPath; + replaceWith = _originalPath; + } + + var result = path?.Replace(find, replaceWith); + return result; + } + + public IEnumerable UpdatePaths(IEnumerable enumerable, PathConversionDirection updateDirection) + { + var updatedPaths = enumerable.Select(i => UpdatePath(i, updateDirection)).ToList(); + return updatedPaths; + } + + public TestCase UpdateTestCase(TestCase testCase, PathConversionDirection updateDirection) + { + testCase.CodeFilePath = UpdatePath(testCase.CodeFilePath, updateDirection); + testCase.Source = UpdatePath(testCase.Source, updateDirection); + return testCase; + } + + public IEnumerable UpdateTestCases(IEnumerable testCases, PathConversionDirection updateDirection) + { + var updatedTestCases = testCases.Select(tc => UpdateTestCase(tc, updateDirection)).ToList(); + + return updatedTestCases; + } + + public TestRunCompleteEventArgs UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, PathConversionDirection updateDirection) + { + UpdateAttachmentSets(testRunCompleteEventArgs.AttachmentSets, updateDirection); + return testRunCompleteEventArgs; + } + + public TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, PathConversionDirection updateDirection) + { + UpdateTestResults(testRunChangedArgs.NewTestResults, updateDirection); + UpdateTestCases(testRunChangedArgs.ActiveTests, updateDirection); + return testRunChangedArgs; + } + + public Collection UpdateAttachmentSets(Collection attachmentSets, PathConversionDirection updateDirection) + { + attachmentSets.Select(i => UpdateAttachmentSet(i, updateDirection)).ToList(); + return attachmentSets; + } + + public ICollection UpdateAttachmentSets(ICollection attachmentSets, PathConversionDirection updateDirection) + { + attachmentSets.Select(i => UpdateAttachmentSet(i, updateDirection)).ToList(); + return attachmentSets; + } + + private AttachmentSet UpdateAttachmentSet(AttachmentSet attachmentSet, PathConversionDirection updateDirection) + { + attachmentSet.Attachments.Select(a => UpdateAttachment(a, updateDirection)).ToList(); + return attachmentSet; + } + + private UriDataAttachment UpdateAttachment(UriDataAttachment attachment, PathConversionDirection updateDirection) + { + // todo: convert uri? + return attachment; + } + + private IEnumerable UpdateTestResults(IEnumerable testResults, PathConversionDirection updateDirection) + { + // The incoming collection is IEnumerable, use foreach to make sure we always do the changes, + // as opposed to using .Select which will never run unless you ask for results (which totally + // did not happen to me, of course). + foreach (var tr in testResults) + { + tr.Attachments.Select(a => UpdateAttachmentSet(a, updateDirection)); + UpdateTestCase(tr.TestCase, updateDirection); + } + + return testResults; + } + + public DiscoveryCriteria UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, PathConversionDirection updateDirection) + { + discoveryCriteria.Package = UpdatePath(discoveryCriteria.Package, updateDirection); + foreach (var adapter in discoveryCriteria.AdapterSourceMap.ToList()) + { + var updatedPaths = UpdatePaths(adapter.Value, updateDirection); + discoveryCriteria.AdapterSourceMap[adapter.Key] = updatedPaths; + } + return discoveryCriteria; + } + + public TestRunCriteriaWithSources UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, PathConversionDirection updateDirection) + { + testRunCriteriaWithSources.AdapterSourceMap.Select(adapter => testRunCriteriaWithSources.AdapterSourceMap[adapter.Key] = UpdatePaths(adapter.Value, updateDirection)); + var package = UpdatePath(testRunCriteriaWithSources.Package, updateDirection); + return new TestRunCriteriaWithSources(testRunCriteriaWithSources.AdapterSourceMap, package, testRunCriteriaWithSources.RunSettings, testRunCriteriaWithSources.TestExecutionContext); + } + + public TestRunCriteriaWithTests UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, PathConversionDirection updateDirection) + { + var tests = UpdateTestCases(testRunCriteriaWithTests.Tests, updateDirection); + var package = UpdatePath(testRunCriteriaWithTests.Package, updateDirection); + return new TestRunCriteriaWithTests(tests, package, testRunCriteriaWithTests.RunSettings, testRunCriteriaWithTests.TestExecutionContext); + } +} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs index dcb20bc1be..7bba35c45e 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs @@ -5,7 +5,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using System; using System.Collections.Generic; -using System.Linq; using System.Threading; using EventHandlers; @@ -22,12 +21,10 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using CrossPlatResources = CrossPlatEngine.Resources.Resources; using ObjectModelConstants = TestPlatform.ObjectModel.Constants; -using System.Collections.ObjectModel; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; -using System.IO; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; -public class TestRequestHandler : ITestRequestHandler +public class TestRequestHandler : ITestRequestHandler, IDeploymentAwareTestRequestHandler { private int _protocolVersion = 1; @@ -52,6 +49,8 @@ public class TestRequestHandler : ITestRequestHandler private Exception _messageProcessingUnrecoverableError; public TestHostConnectionInfo ConnectionInfo { get; set; } + string IDeploymentAwareTestRequestHandler.LocalPath { get; set; } + string IDeploymentAwareTestRequestHandler.RemotePath { get; set; } /// /// Initializes a new instance of the . @@ -104,13 +103,11 @@ protected TestRequestHandler(IDataSerializer dataSerializer, ICommunicationEndpo /// public virtual void InitializeCommunication() { - // soo beautiful! - var localPath = Environment.GetEnvironmentVariable("--local-path"); - var remotePath = Environment.GetEnvironmentVariable("--remote-path"); - - if (!string.IsNullOrWhiteSpace(localPath) && !string.IsNullOrEmpty(remotePath)) + if (this is IDeploymentAwareTestRequestHandler self + && !string.IsNullOrWhiteSpace(self.LocalPath) + && !string.IsNullOrEmpty(self.RemotePath)) { - _pathConverter = new PathConverter(localPath, remotePath, _fileHelper); + _pathConverter = new PathConverter(self.LocalPath, self.RemotePath, _fileHelper); } else { @@ -164,7 +161,7 @@ public void Close() /// public void SendTestCases(IEnumerable discoveredTestCases) { - var updatedTestCases = _pathConverter.UpdateTestCases(discoveredTestCases, Direction.Send); + var updatedTestCases = _pathConverter.UpdateTestCases(discoveredTestCases, PathConversionDirection.Send); var data = _dataSerializer.SerializePayload(MessageType.TestCasesFound, updatedTestCases, _protocolVersion); SendData(data); } @@ -172,7 +169,7 @@ public void SendTestCases(IEnumerable discoveredTestCases) /// public void SendTestRunStatistics(TestRunChangedEventArgs testRunChangedArgs) { - var updatedTestRunChangedEventArgs = _pathConverter.UpdateTestRunChangedEventArgs(testRunChangedArgs, Direction.Send); + var updatedTestRunChangedEventArgs = _pathConverter.UpdateTestRunChangedEventArgs(testRunChangedArgs, PathConversionDirection.Send); var data = _dataSerializer.SerializePayload(MessageType.TestRunStatsChange, updatedTestRunChangedEventArgs, _protocolVersion); SendData(data); } @@ -204,16 +201,16 @@ public void SendExecutionComplete( curentArgs.IsCanceled, curentArgs.IsAborted, _messageProcessingUnrecoverableError, - _pathConverter.UpdateAttachmentSets(curentArgs.AttachmentSets, Direction.Send), curentArgs.InvokedDataCollectors, curentArgs.ElapsedTimeInRunningTests + _pathConverter.UpdateAttachmentSets(curentArgs.AttachmentSets, PathConversionDirection.Send), curentArgs.InvokedDataCollectors, curentArgs.ElapsedTimeInRunningTests ); } var data = _dataSerializer.SerializePayload( MessageType.ExecutionComplete, new TestRunCompletePayload { - TestRunCompleteArgs = _pathConverter.UpdateTestRunCompleteEventArgs(testRunCompleteArgs, Direction.Send), - LastRunTests = _pathConverter.UpdateTestRunChangedEventArgs(lastChunkArgs, Direction.Send), - RunAttachments = _pathConverter.UpdateAttachmentSets(runContextAttachments, Direction.Send), + TestRunCompleteArgs = _pathConverter.UpdateTestRunCompleteEventArgs(testRunCompleteArgs, PathConversionDirection.Send), + LastRunTests = _pathConverter.UpdateTestRunChangedEventArgs(lastChunkArgs, PathConversionDirection.Send), + RunAttachments = _pathConverter.UpdateAttachmentSets(runContextAttachments, PathConversionDirection.Send), ExecutorUris = executorUris }, _protocolVersion); @@ -228,7 +225,7 @@ public void DiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventA new DiscoveryCompletePayload { TotalTests = discoveryCompleteEventArgs.TotalCount, - LastDiscoveredTests = discoveryCompleteEventArgs.IsAborted ? null : _pathConverter.UpdateTestCases(lastChunk, Direction.Send), + LastDiscoveredTests = discoveryCompleteEventArgs.IsAborted ? null : _pathConverter.UpdateTestCases(lastChunk, PathConversionDirection.Send), IsAborted = discoveryCompleteEventArgs.IsAborted, Metrics = discoveryCompleteEventArgs.Metrics }, @@ -358,7 +355,7 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec { _testHostManagerFactoryReady.Wait(); var discoveryEventsHandler = new TestDiscoveryEventHandler(this); - var pathToAdditionalExtensions = _pathConverter.UpdatePaths(_dataSerializer.DeserializePayload>(message), Direction.Receive); + var pathToAdditionalExtensions = _pathConverter.UpdatePaths(_dataSerializer.DeserializePayload>(message), PathConversionDirection.Receive); Action job = () => { EqtTrace.Info("TestRequestHandler.OnMessageReceived: Running job '{0}'.", message.MessageType); @@ -382,7 +379,7 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec { _testHostManagerFactoryReady.Wait(); var discoveryEventsHandler = new TestDiscoveryEventHandler(this); - var discoveryCriteria = _pathConverter.UpdateDiscoveryCriteria(_dataSerializer.DeserializePayload(message), Direction.Receive); + var discoveryCriteria = _pathConverter.UpdateDiscoveryCriteria(_dataSerializer.DeserializePayload(message), PathConversionDirection.Receive); Action job = () => { @@ -409,7 +406,7 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec { _testHostManagerFactoryReady.Wait(); var testInitializeEventsHandler = new TestInitializeEventsHandler(this); - var pathToAdditionalExtensions = _pathConverter.UpdatePaths(_dataSerializer.DeserializePayload>(message), Direction.Receive); + var pathToAdditionalExtensions = _pathConverter.UpdatePaths(_dataSerializer.DeserializePayload>(message), PathConversionDirection.Receive); Action job = () => { EqtTrace.Info("TestRequestHandler.OnMessageReceived: Running job '{0}'.", message.MessageType); @@ -433,7 +430,7 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec { var testRunEventsHandler = new TestRunEventsHandler(this); _testHostManagerFactoryReady.Wait(); - var testRunCriteriaWithSources = _pathConverter.UpdateTestRunCriteriaWithSources(_dataSerializer.DeserializePayload(message), Direction.Receive); + var testRunCriteriaWithSources = _pathConverter.UpdateTestRunCriteriaWithSources(_dataSerializer.DeserializePayload(message), PathConversionDirection.Receive); Action job = () => { EqtTrace.Info("TestRequestHandler.OnMessageReceived: Running job '{0}'.", message.MessageType); @@ -464,7 +461,7 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec { var testRunEventsHandler = new TestRunEventsHandler(this); _testHostManagerFactoryReady.Wait(); - var testRunCriteriaWithTests = _pathConverter.UpdateTestRunCriteriaWithTests(_dataSerializer.DeserializePayload(message), Direction.Receive); + var testRunCriteriaWithTests = _pathConverter.UpdateTestRunCriteriaWithTests(_dataSerializer.DeserializePayload(message), PathConversionDirection.Receive); Action job = () => { @@ -561,229 +558,3 @@ private void SendData(string data) _channel.Send(data); } } - -internal class NullPathConverter : IPathConverter -{ - Collection IPathConverter.UpdateAttachmentSets(Collection attachmentSets, Direction updateDirection) - { - return attachmentSets; - } - - ICollection IPathConverter.UpdateAttachmentSets(ICollection attachmentSets, Direction updateDirection) - { - return attachmentSets; - } - - DiscoveryCriteria IPathConverter.UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, Direction updateDirection) - { - return discoveryCriteria; - } - - string IPathConverter.UpdatePath(string path, Direction updateDirection) - { - return path; - } - - IEnumerable IPathConverter.UpdatePaths(IEnumerable enumerable, Direction updateDirection) - { - return enumerable; - } - - TestCase IPathConverter.UpdateTestCase(TestCase testCase, Direction updateDirection) - { - return testCase; - } - - IEnumerable IPathConverter.UpdateTestCases(IEnumerable testCases, Direction updateDirection) - { - return testCases; - } - - TestRunChangedEventArgs IPathConverter.UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, Direction updateDirection) - { - return testRunChangedArgs; - } - - TestRunCompleteEventArgs IPathConverter.UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, Direction updateDirection) - { - return testRunCompleteEventArgs; - } - - TestRunCriteriaWithSources IPathConverter.UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, Direction updateDirection) - { - return testRunCriteriaWithSources; - } - - TestRunCriteriaWithTests IPathConverter.UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, Direction updateDirection) - { - return testRunCriteriaWithTests; - } -} - -internal enum Direction -{ - Receive, - Send -} - -internal class PathConverter : IPathConverter -{ - // The path on this computer to which we deployed the test dll and test runner - private readonly string _deploymentPath = ""; - // The path on the remote system where test dll was originally placed, and from which we - // copied it to this system. For vstest.console, which is on the other side of this, the names - // are inverted, it sends us their local path, and thinks about our local path as remote. - private readonly string _originalPath = ""; - - public PathConverter(string originalPath, string deploymentPath, IFileHelper fileHelper) - { - _originalPath = fileHelper.GetFullPath(originalPath).TrimEnd('\\').TrimEnd('/') + Path.DirectorySeparatorChar; - _deploymentPath = fileHelper.GetFullPath(deploymentPath).TrimEnd('\\').TrimEnd('/') + Path.DirectorySeparatorChar; - } - - public string UpdatePath(string path, Direction updateDirection) - { - string find; - string replaceWith; - if (updateDirection == Direction.Receive) - { - // Request is incoming, the path that is local to the sender (for us that is "remote" path) - // needs to be replaced with our path - find = _originalPath; - replaceWith = _deploymentPath; - } - else - { - find = _deploymentPath; - replaceWith = _originalPath; - } - - var result = path?.Replace(find, replaceWith); - return result; - } - - public IEnumerable UpdatePaths(IEnumerable enumerable, Direction updateDirection) - { - var updatedPaths = enumerable.Select(i => UpdatePath(i, updateDirection)).ToList(); - return updatedPaths; - } - - public TestCase UpdateTestCase(TestCase testCase, Direction updateDirection) - { - testCase.CodeFilePath = UpdatePath(testCase.CodeFilePath, updateDirection); - testCase.Source = UpdatePath(testCase.Source, updateDirection); - return testCase; - } - - public IEnumerable UpdateTestCases(IEnumerable testCases, Direction updateDirection) - { - var updatedTestCases = testCases.Select(tc => UpdateTestCase(tc, updateDirection)).ToList(); - - return updatedTestCases; - } - - public TestRunCompleteEventArgs UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, Direction updateDirection) - { - UpdateAttachmentSets(testRunCompleteEventArgs.AttachmentSets, updateDirection); - return testRunCompleteEventArgs; - } - - public TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, Direction updateDirection) - { - UpdateTestResults(testRunChangedArgs.NewTestResults, updateDirection); - UpdateTestCases(testRunChangedArgs.ActiveTests, updateDirection); - return testRunChangedArgs; - } - - public Collection UpdateAttachmentSets(Collection attachmentSets, Direction updateDirection) - { - attachmentSets.Select(i => UpdateAttachmentSet(i, updateDirection)).ToList(); - return attachmentSets; - } - - public ICollection UpdateAttachmentSets(ICollection attachmentSets, Direction updateDirection) - { - attachmentSets.Select(i => UpdateAttachmentSet(i, updateDirection)).ToList(); - return attachmentSets; - } - - private AttachmentSet UpdateAttachmentSet(AttachmentSet attachmentSet, Direction updateDirection) - { - attachmentSet.Attachments.Select(a => UpdateAttachment(a, updateDirection)).ToList(); - return attachmentSet; - } - - private UriDataAttachment UpdateAttachment(UriDataAttachment attachment, Direction updateDirection) - { - // todo: convert uri? - return attachment; - } - - private IEnumerable UpdateTestResults(IEnumerable testResults, Direction updateDirection) - { - // The incoming collection is IEnumerable, use foreach to make sure we always do the changes, - // as opposed to using .Select which will never run unless you ask for results (which totally - // did not happen to me, of course). - foreach (var tr in testResults) - { - tr.Attachments.Select(a => UpdateAttachmentSet(a, updateDirection)); - UpdateTestCase(tr.TestCase, updateDirection); - } - - return testResults; - } - - public DiscoveryCriteria UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, Direction updateDirection) - { - discoveryCriteria.Package = UpdatePath(discoveryCriteria.Package, updateDirection); - foreach (var adapter in discoveryCriteria.AdapterSourceMap.ToList()) - { - var updatedPaths = UpdatePaths(adapter.Value, updateDirection); - discoveryCriteria.AdapterSourceMap[adapter.Key] = updatedPaths; - } - return discoveryCriteria; - } - - public TestRunCriteriaWithSources UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, Direction updateDirection) - { - testRunCriteriaWithSources.AdapterSourceMap.Select(adapter => testRunCriteriaWithSources.AdapterSourceMap[adapter.Key] = UpdatePaths(adapter.Value, updateDirection)); - var package = UpdatePath(testRunCriteriaWithSources.Package, updateDirection); - return new TestRunCriteriaWithSources(testRunCriteriaWithSources.AdapterSourceMap, package, testRunCriteriaWithSources.RunSettings, testRunCriteriaWithSources.TestExecutionContext); - } - - public TestRunCriteriaWithTests UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, Direction updateDirection) - { - var tests = UpdateTestCases(testRunCriteriaWithTests.Tests, updateDirection); - var package = UpdatePath(testRunCriteriaWithTests.Package, updateDirection); - return new TestRunCriteriaWithTests(tests, package, testRunCriteriaWithTests.RunSettings, testRunCriteriaWithTests.TestExecutionContext); - } -} - -internal interface IPathConverter -{ - internal string UpdatePath(string path, Direction updateDirection); - - - internal IEnumerable UpdatePaths(IEnumerable enumerable, Direction updateDirection); - - internal TestCase UpdateTestCase(TestCase testCase, Direction updateDirection); - - internal IEnumerable UpdateTestCases(IEnumerable testCases, Direction updateDirection); - - - internal TestRunCompleteEventArgs UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, Direction updateDirection); - - - internal TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, Direction updateDirection); - - - internal Collection UpdateAttachmentSets(Collection attachmentSets, Direction updateDirection); - - internal ICollection UpdateAttachmentSets(ICollection attachmentSets, Direction updateDirection); - - internal DiscoveryCriteria UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, Direction updateDirection); - - internal TestRunCriteriaWithSources UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, Direction updateDirection); - - internal TestRunCriteriaWithTests UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, Direction updateDirection); -} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs index b52f4adf02..b1f64f32b8 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs @@ -9,7 +9,24 @@ [assembly: InternalsVisibleTo("datacollector, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("datacollector.PlatformTests, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("testhost, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net452, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net46, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net461, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net462, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net47, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net471, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net472, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net48, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("testhost.x86, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net452.x86, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net46.x86, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net461.x86, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net462.x86, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net47.x86, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net471.x86, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net472.x86, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net48.x86, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("vstest.console, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] +[assembly: InternalsVisibleTo("ConsoleApp1, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] diff --git a/src/testhost.x86/DefaultEngineInvoker.cs b/src/testhost.x86/DefaultEngineInvoker.cs index 9dbd7588d4..562577abcd 100644 --- a/src/testhost.x86/DefaultEngineInvoker.cs +++ b/src/testhost.x86/DefaultEngineInvoker.cs @@ -88,10 +88,15 @@ public void Invoke(IDictionary argsDictionary) { InitializeEqtTrace(argsDictionary); - if (argsDictionary.ContainsKey(RemotePath) && argsDictionary.ContainsKey(LocalPath)) + // We don't have a way to pass these values to TestRequestHandler directly + // beacuse of it's public interface, we work around that by making it implement a second interface + if (_requestHandler is IDeploymentAwareTestRequestHandler deployedHandler) { - Environment.SetEnvironmentVariable(LocalPath, argsDictionary[LocalPath]); - Environment.SetEnvironmentVariable(RemotePath, argsDictionary[RemotePath]); + if (argsDictionary.ContainsKey(RemotePath) && argsDictionary.ContainsKey(LocalPath)) + { + deployedHandler.LocalPath = argsDictionary[LocalPath]; + deployedHandler.RemotePath = argsDictionary[RemotePath]; + } } if (EqtTrace.IsVerboseEnabled) From 6177945582e6867401114f8abec826ca0092faeb Mon Sep 17 00:00:00 2001 From: nohwnd Date: Mon, 14 Feb 2022 16:55:30 +0100 Subject: [PATCH 05/12] Spaces --- playground/TestPlatform.Playground/Program.cs | 53 +---------------- .../EventHandlers/IPathConverter.cs | 6 +- .../Hosting/DefaultTestHostManager.cs | 59 ------------------- 3 files changed, 2 insertions(+), 116 deletions(-) diff --git a/playground/TestPlatform.Playground/Program.cs b/playground/TestPlatform.Playground/Program.cs index 933cb3ae7c..44264b4a40 100644 --- a/playground/TestPlatform.Playground/Program.cs +++ b/playground/TestPlatform.Playground/Program.cs @@ -57,13 +57,7 @@ static void Main(string[] args) }; var options = new TestPlatformOptions(); - var discoveryHandler = new TestDiscoveryHandler(); - r.DiscoverTests(sources, sourceSettings, options, discoveryHandler); - if (File.Exists(sources[0])) - { - throw new Exception($"File {sources[0]} exists, but it should not because we moved it during deployment!"); - } - r.RunTestsWithCustomTestHost(discoveryHandler.DiscoveredTestCases, sourceSettings, options, new TestRunHandler(), new DebuggerTestHostLauncher()); + r.RunTestsWithCustomTestHost(sources, sourceSettings, options, new TestRunHandler(), new DebuggerTestHostLauncher()); } public class TestRunHandler : ITestRunEventsHandler @@ -109,51 +103,6 @@ private string WriteTests(IEnumerable testCases) } } - public class TestDiscoveryHandler : ITestDiscoveryEventsHandler2 - { - public List DiscoveredTestCases { get; } = new List(); - public List Messages { get; } = new List(); - - public void HandleDiscoveredTests(IEnumerable discoveredTestCases) - { - if (discoveredTestCases != null) - { - DiscoveredTestCases.AddRange(discoveredTestCases); - Console.WriteLine($"[DISCOVERY UPDATE] {WriteTests(discoveredTestCases)}"); - } - } - - public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable lastChunk) - { - if (lastChunk != null) - { - DiscoveredTestCases.AddRange(lastChunk); - Console.WriteLine($"[DISCOVERY COMPLETE] {WriteTests(lastChunk)}"); - } - } - - public void HandleLogMessage(TestMessageLevel level, string message) - { - Messages.Add($"[{level}]: {message}"); - Console.WriteLine(($"[{level}]: {message}")); - } - - public void HandleRawMessage(string rawMessage) - { - Console.WriteLine(($"[RAWMESSAGE]: {rawMessage}")); - } - - private string WriteTests(IEnumerable testResults) - { - return WriteTests(testResults?.Select(t => t.TestCase)); - } - - private string WriteTests(IEnumerable testCases) - { - return testCases == null ? null : "\t" + string.Join("\n\t", testCases.Select(r => r.DisplayName)); - } - } - internal class DebuggerTestHostLauncher : ITestHostLauncher2 { public bool IsDebug => true; diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs index 62ab4129c7..c625b3c5e1 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs @@ -12,20 +12,16 @@ internal interface IPathConverter { internal string UpdatePath(string path, PathConversionDirection updateDirection); - internal IEnumerable UpdatePaths(IEnumerable enumerable, PathConversionDirection updateDirection); internal TestCase UpdateTestCase(TestCase testCase, PathConversionDirection updateDirection); internal IEnumerable UpdateTestCases(IEnumerable testCases, PathConversionDirection updateDirection); - internal TestRunCompleteEventArgs UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, PathConversionDirection updateDirection); - internal TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, PathConversionDirection updateDirection); - internal Collection UpdateAttachmentSets(Collection attachmentSets, PathConversionDirection updateDirection); internal ICollection UpdateAttachmentSets(ICollection attachmentSets, PathConversionDirection updateDirection); @@ -35,4 +31,4 @@ internal interface IPathConverter internal TestRunCriteriaWithSources UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, PathConversionDirection updateDirection); internal TestRunCriteriaWithTests UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, PathConversionDirection updateDirection); -} \ No newline at end of file +} diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index 968fd46da1..434aacec54 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -163,8 +163,6 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( testhostProcessPath = Path.Combine(currentWorkingDirectory, testHostProcessName); } - - if (!Shared) { // Not sharing the host which means we need to pass the test assembly path as argument @@ -172,35 +170,6 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( argumentsString += " --testsourcepath " + sources.FirstOrDefault().AddDoubleQuote(); } - // do something like deploy, we copy the whole folder, and remote the sources - // from the original folder - var localDirectory = Path.GetDirectoryName(sources.FirstOrDefault()); - var remoteDirectory = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(sources.FirstOrDefault()), "..", "remote")); - - - // delete and copy only if sources exist, we will delete the test.dll few lines below to make - // sure we are not using just the one from the original path, instead from the deploy - // path, but because we start new testhost after discovery, we would be deleting the - // only copy of tests.dll, and copying the original folder without it. - if (sources.All(File.Exists)) - { - if (Directory.Exists(remoteDirectory)) - { - Directory.Delete(remoteDirectory, true); - } - - Copy(localDirectory, remoteDirectory); - sources.ToList().ForEach(File.Delete); - } - // deploy end - - - // this is the path where we deployed the files - argumentsString += " --remote-path " + remoteDirectory; - - // this is the path where the files were originally - argumentsString += " --local-path " + localDirectory; - EqtTrace.Verbose("DefaultTestHostmanager: Full path of {0} is {1}", testHostProcessName, testhostProcessPath); var launcherPath = testhostProcessPath; @@ -224,34 +193,6 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( EnvironmentVariables = environmentVariables ?? new Dictionary(), WorkingDirectory = processWorkingDirectory }; - - void Copy(string sourceDirectory, string targetDirectory) - { - var diSource = new DirectoryInfo(sourceDirectory); - var diTarget = new DirectoryInfo(targetDirectory); - - CopyAll(diSource, diTarget); - } - - void CopyAll(DirectoryInfo source, DirectoryInfo target) - { - Directory.CreateDirectory(target.FullName); - - // Copy each file into the new directory. - foreach (FileInfo fi in source.GetFiles()) - { - Console.WriteLine(@"Copying {0}\{1}", target.FullName, fi.Name); - fi.CopyTo(Path.Combine(target.FullName, fi.Name), true); - } - - // Copy each subdirectory using recursion. - foreach (DirectoryInfo diSourceSubDir in source.GetDirectories()) - { - DirectoryInfo nextTargetSubDir = - target.CreateSubdirectory(diSourceSubDir.Name); - CopyAll(diSourceSubDir, nextTargetSubDir); - } - } } /// From d97230d104191ea86e6960af4b8cf96ba76e93a8 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Mon, 14 Feb 2022 17:03:35 +0100 Subject: [PATCH 06/12] Revert playgroun --- .../TestPlatform.Playground/TestPlatform.Playground.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/TestPlatform.Playground/TestPlatform.Playground.csproj b/playground/TestPlatform.Playground/TestPlatform.Playground.csproj index f121a18af7..d73746f16e 100644 --- a/playground/TestPlatform.Playground/TestPlatform.Playground.csproj +++ b/playground/TestPlatform.Playground/TestPlatform.Playground.csproj @@ -39,7 +39,7 @@ - + From 08f9b9432a492efa7ac0cf6bb72b96c844476212 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Tue, 15 Feb 2022 12:50:02 +0100 Subject: [PATCH 07/12] Fixes --- .../EventHandlers/IPathConverter.cs | 22 ++++---- .../EventHandlers/NullPathConverter.cs | 55 ++++--------------- .../EventHandlers/PathConverter.cs | 13 +++-- 3 files changed, 30 insertions(+), 60 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs index c625b3c5e1..69327376ea 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs @@ -10,25 +10,25 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; internal interface IPathConverter { - internal string UpdatePath(string path, PathConversionDirection updateDirection); + string? UpdatePath(string? path, PathConversionDirection updateDirection); - internal IEnumerable UpdatePaths(IEnumerable enumerable, PathConversionDirection updateDirection); + IEnumerable UpdatePaths(IEnumerable enumerable, PathConversionDirection updateDirection); - internal TestCase UpdateTestCase(TestCase testCase, PathConversionDirection updateDirection); + TestCase UpdateTestCase(TestCase testCase, PathConversionDirection updateDirection); - internal IEnumerable UpdateTestCases(IEnumerable testCases, PathConversionDirection updateDirection); + IEnumerable UpdateTestCases(IEnumerable testCases, PathConversionDirection updateDirection); - internal TestRunCompleteEventArgs UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, PathConversionDirection updateDirection); + TestRunCompleteEventArgs UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, PathConversionDirection updateDirection); - internal TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, PathConversionDirection updateDirection); + TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, PathConversionDirection updateDirection); - internal Collection UpdateAttachmentSets(Collection attachmentSets, PathConversionDirection updateDirection); + Collection UpdateAttachmentSets(Collection attachmentSets, PathConversionDirection updateDirection); - internal ICollection UpdateAttachmentSets(ICollection attachmentSets, PathConversionDirection updateDirection); + ICollection UpdateAttachmentSets(ICollection attachmentSets, PathConversionDirection updateDirection); - internal DiscoveryCriteria UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, PathConversionDirection updateDirection); + DiscoveryCriteria UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, PathConversionDirection updateDirection); - internal TestRunCriteriaWithSources UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, PathConversionDirection updateDirection); + TestRunCriteriaWithSources UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, PathConversionDirection updateDirection); - internal TestRunCriteriaWithTests UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, PathConversionDirection updateDirection); + TestRunCriteriaWithTests UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, PathConversionDirection updateDirection); } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs index 5a1ef33aef..23bbc6d957 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs @@ -10,58 +10,25 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; internal class NullPathConverter : IPathConverter { - Collection IPathConverter.UpdateAttachmentSets(Collection attachmentSets, PathConversionDirection updateDirection) - { - return attachmentSets; - } + Collection IPathConverter.UpdateAttachmentSets(Collection attachmentSets, PathConversionDirection _) => attachmentSets; - ICollection IPathConverter.UpdateAttachmentSets(ICollection attachmentSets, PathConversionDirection updateDirection) - { - return attachmentSets; - } + ICollection IPathConverter.UpdateAttachmentSets(ICollection attachmentSets, PathConversionDirection _) => attachmentSets; - DiscoveryCriteria IPathConverter.UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, PathConversionDirection updateDirection) - { - return discoveryCriteria; - } + DiscoveryCriteria IPathConverter.UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, PathConversionDirection _) => discoveryCriteria; - string IPathConverter.UpdatePath(string path, PathConversionDirection updateDirection) - { - return path; - } + string IPathConverter.UpdatePath(string path, PathConversionDirection _) => path; - IEnumerable IPathConverter.UpdatePaths(IEnumerable enumerable, PathConversionDirection updateDirection) - { - return enumerable; - } + IEnumerable IPathConverter.UpdatePaths(IEnumerable enumerable, PathConversionDirection _) => enumerable; - TestCase IPathConverter.UpdateTestCase(TestCase testCase, PathConversionDirection updateDirection) - { - return testCase; - } + TestCase IPathConverter.UpdateTestCase(TestCase testCase, PathConversionDirection _) => testCase; - IEnumerable IPathConverter.UpdateTestCases(IEnumerable testCases, PathConversionDirection updateDirection) - { - return testCases; - } + IEnumerable IPathConverter.UpdateTestCases(IEnumerable testCases, PathConversionDirection _) => testCases; - TestRunChangedEventArgs IPathConverter.UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, PathConversionDirection updateDirection) - { - return testRunChangedArgs; - } + TestRunChangedEventArgs IPathConverter.UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, PathConversionDirection _) => testRunChangedArgs; - TestRunCompleteEventArgs IPathConverter.UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, PathConversionDirection updateDirection) - { - return testRunCompleteEventArgs; - } + TestRunCompleteEventArgs IPathConverter.UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, PathConversionDirection _) => testRunCompleteEventArgs; - TestRunCriteriaWithSources IPathConverter.UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, PathConversionDirection updateDirection) - { - return testRunCriteriaWithSources; - } + TestRunCriteriaWithSources IPathConverter.UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, PathConversionDirection _) => testRunCriteriaWithSources; - TestRunCriteriaWithTests IPathConverter.UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, PathConversionDirection updateDirection) - { - return testRunCriteriaWithTests; - } + TestRunCriteriaWithTests IPathConverter.UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, PathConversionDirection _) => testRunCriteriaWithTests; } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs index 14d0f6ccf6..aad078a0aa 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs @@ -26,8 +26,11 @@ public PathConverter(string originalPath, string deploymentPath, IFileHelper fil _deploymentPath = fileHelper.GetFullPath(deploymentPath).TrimEnd('\\').TrimEnd('/') + Path.DirectorySeparatorChar; } - public string UpdatePath(string path, PathConversionDirection updateDirection) + public string? UpdatePath(string? path, PathConversionDirection updateDirection) { + if (path == null) + return path; + string find; string replaceWith; if (updateDirection == PathConversionDirection.Receive) @@ -82,23 +85,23 @@ public TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEvent public Collection UpdateAttachmentSets(Collection attachmentSets, PathConversionDirection updateDirection) { - attachmentSets.Select(i => UpdateAttachmentSet(i, updateDirection)).ToList(); + attachmentSets.ToList().ForEach(i => UpdateAttachmentSet(i, updateDirection)); return attachmentSets; } public ICollection UpdateAttachmentSets(ICollection attachmentSets, PathConversionDirection updateDirection) { - attachmentSets.Select(i => UpdateAttachmentSet(i, updateDirection)).ToList(); + attachmentSets.ToList().ForEach(i => UpdateAttachmentSet(i, updateDirection)); return attachmentSets; } private AttachmentSet UpdateAttachmentSet(AttachmentSet attachmentSet, PathConversionDirection updateDirection) { - attachmentSet.Attachments.Select(a => UpdateAttachment(a, updateDirection)).ToList(); + attachmentSet.Attachments.ToList().ForEach(a => UpdateAttachment(a, updateDirection)); return attachmentSet; } - private UriDataAttachment UpdateAttachment(UriDataAttachment attachment, PathConversionDirection updateDirection) + private UriDataAttachment UpdateAttachment(UriDataAttachment attachment, PathConversionDirection _) { // todo: convert uri? return attachment; From 8f00557c1d069c7f6f64c619841e903df3f0267a Mon Sep 17 00:00:00 2001 From: nohwnd Date: Tue, 15 Feb 2022 14:28:40 +0100 Subject: [PATCH 08/12] Review fixes --- .../EventHandlers/IPathConverter.cs | 3 +- .../EventHandlers/NullPathConverter.cs | 12 ++++- .../EventHandlers/PathConverter.cs | 54 ++++++++++--------- .../EventHandlers/TestRequestHandler.cs | 8 +-- .../Friends.cs | 1 - 5 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs index 69327376ea..25519e89a4 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; + using System.Collections.Generic; using ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -12,7 +13,7 @@ internal interface IPathConverter { string? UpdatePath(string? path, PathConversionDirection updateDirection); - IEnumerable UpdatePaths(IEnumerable enumerable, PathConversionDirection updateDirection); + IEnumerable UpdatePaths(IEnumerable paths, PathConversionDirection updateDirection); TestCase UpdateTestCase(TestCase testCase, PathConversionDirection updateDirection); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs index 23bbc6d957..cb5ce19c44 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs @@ -2,23 +2,31 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; + using System.Collections.Generic; using ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using System.Collections.ObjectModel; +using System; internal class NullPathConverter : IPathConverter { + private static readonly Lazy LazyInstance= new(() => new NullPathConverter()); + + private NullPathConverter() { } + + public static NullPathConverter Instance => LazyInstance.Value; + Collection IPathConverter.UpdateAttachmentSets(Collection attachmentSets, PathConversionDirection _) => attachmentSets; ICollection IPathConverter.UpdateAttachmentSets(ICollection attachmentSets, PathConversionDirection _) => attachmentSets; DiscoveryCriteria IPathConverter.UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, PathConversionDirection _) => discoveryCriteria; - string IPathConverter.UpdatePath(string path, PathConversionDirection _) => path; + string? IPathConverter.UpdatePath(string? path, PathConversionDirection _) => path; - IEnumerable IPathConverter.UpdatePaths(IEnumerable enumerable, PathConversionDirection _) => enumerable; + IEnumerable IPathConverter.UpdatePaths(IEnumerable paths, PathConversionDirection _) => paths; TestCase IPathConverter.UpdateTestCase(TestCase testCase, PathConversionDirection _) => testCase; diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs index aad078a0aa..6b7b1cdd33 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; + using System.Collections.Generic; using System.Linq; using ObjectModel; @@ -11,6 +12,13 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using System.IO; +/// +/// Converts paths in received and sent objects, to make testhost seem like it run a local test, +/// while it was in fact running a test on a remote system, in a totally different path. This is for UWP which +/// does testhost deployment. +/// The modifications here rely on combination of side-effects, and actually replacing the values, because +/// we cannot modify the properties on our public objects, and add setters. +/// internal class PathConverter : IPathConverter { // The path on this computer to which we deployed the test dll and test runner @@ -20,7 +28,7 @@ internal class PathConverter : IPathConverter // are inverted, it sends us their local path, and thinks about our local path as remote. private readonly string _originalPath = ""; - public PathConverter(string originalPath, string deploymentPath, IFileHelper fileHelper) + public PathConverter(string originalPath!!, string deploymentPath!!, IFileHelper fileHelper!!) { _originalPath = fileHelper.GetFullPath(originalPath).TrimEnd('\\').TrimEnd('/') + Path.DirectorySeparatorChar; _deploymentPath = fileHelper.GetFullPath(deploymentPath).TrimEnd('\\').TrimEnd('/') + Path.DirectorySeparatorChar; @@ -50,78 +58,72 @@ public PathConverter(string originalPath, string deploymentPath, IFileHelper fil return result; } - public IEnumerable UpdatePaths(IEnumerable enumerable, PathConversionDirection updateDirection) + public IEnumerable UpdatePaths(IEnumerable paths!!, PathConversionDirection updateDirection) { - var updatedPaths = enumerable.Select(i => UpdatePath(i, updateDirection)).ToList(); - return updatedPaths; + return paths.Select(i => UpdatePath(i, updateDirection)).ToList(); } - public TestCase UpdateTestCase(TestCase testCase, PathConversionDirection updateDirection) + public TestCase UpdateTestCase(TestCase testCase!!, PathConversionDirection updateDirection) { testCase.CodeFilePath = UpdatePath(testCase.CodeFilePath, updateDirection); testCase.Source = UpdatePath(testCase.Source, updateDirection); return testCase; } - public IEnumerable UpdateTestCases(IEnumerable testCases, PathConversionDirection updateDirection) + public IEnumerable UpdateTestCases(IEnumerable testCases!!, PathConversionDirection updateDirection) { - var updatedTestCases = testCases.Select(tc => UpdateTestCase(tc, updateDirection)).ToList(); - - return updatedTestCases; + testCases.ToList().ForEach(tc => UpdateTestCase(tc, updateDirection)); + return testCases; } - public TestRunCompleteEventArgs UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs, PathConversionDirection updateDirection) + public TestRunCompleteEventArgs UpdateTestRunCompleteEventArgs(TestRunCompleteEventArgs testRunCompleteEventArgs!!, PathConversionDirection updateDirection) { UpdateAttachmentSets(testRunCompleteEventArgs.AttachmentSets, updateDirection); return testRunCompleteEventArgs; } - public TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs, PathConversionDirection updateDirection) + public TestRunChangedEventArgs UpdateTestRunChangedEventArgs(TestRunChangedEventArgs testRunChangedArgs!!, PathConversionDirection updateDirection) { UpdateTestResults(testRunChangedArgs.NewTestResults, updateDirection); UpdateTestCases(testRunChangedArgs.ActiveTests, updateDirection); return testRunChangedArgs; } - public Collection UpdateAttachmentSets(Collection attachmentSets, PathConversionDirection updateDirection) + public Collection UpdateAttachmentSets(Collection attachmentSets!!, PathConversionDirection updateDirection) { attachmentSets.ToList().ForEach(i => UpdateAttachmentSet(i, updateDirection)); return attachmentSets; } - public ICollection UpdateAttachmentSets(ICollection attachmentSets, PathConversionDirection updateDirection) + public ICollection UpdateAttachmentSets(ICollection attachmentSets!!, PathConversionDirection updateDirection) { attachmentSets.ToList().ForEach(i => UpdateAttachmentSet(i, updateDirection)); return attachmentSets; } - private AttachmentSet UpdateAttachmentSet(AttachmentSet attachmentSet, PathConversionDirection updateDirection) + private AttachmentSet UpdateAttachmentSet(AttachmentSet attachmentSet!!, PathConversionDirection updateDirection) { attachmentSet.Attachments.ToList().ForEach(a => UpdateAttachment(a, updateDirection)); return attachmentSet; } - private UriDataAttachment UpdateAttachment(UriDataAttachment attachment, PathConversionDirection _) + private UriDataAttachment UpdateAttachment(UriDataAttachment attachment!!, PathConversionDirection _) { - // todo: convert uri? + // todo: convert uri? https://github.com/microsoft/vstest/issues/3367 return attachment; } - private IEnumerable UpdateTestResults(IEnumerable testResults, PathConversionDirection updateDirection) + private IEnumerable UpdateTestResults(IEnumerable testResults!!, PathConversionDirection updateDirection) { - // The incoming collection is IEnumerable, use foreach to make sure we always do the changes, - // as opposed to using .Select which will never run unless you ask for results (which totally - // did not happen to me, of course). foreach (var tr in testResults) { - tr.Attachments.Select(a => UpdateAttachmentSet(a, updateDirection)); + UpdateAttachmentSets(tr.Attachments, updateDirection); UpdateTestCase(tr.TestCase, updateDirection); } - return testResults; } - public DiscoveryCriteria UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria, PathConversionDirection updateDirection) + public DiscoveryCriteria UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCriteria!!, PathConversionDirection updateDirection) { discoveryCriteria.Package = UpdatePath(discoveryCriteria.Package, updateDirection); foreach (var adapter in discoveryCriteria.AdapterSourceMap.ToList()) @@ -132,14 +134,14 @@ public DiscoveryCriteria UpdateDiscoveryCriteria(DiscoveryCriteria discoveryCrit return discoveryCriteria; } - public TestRunCriteriaWithSources UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources, PathConversionDirection updateDirection) + public TestRunCriteriaWithSources UpdateTestRunCriteriaWithSources(TestRunCriteriaWithSources testRunCriteriaWithSources!!, PathConversionDirection updateDirection) { - testRunCriteriaWithSources.AdapterSourceMap.Select(adapter => testRunCriteriaWithSources.AdapterSourceMap[adapter.Key] = UpdatePaths(adapter.Value, updateDirection)); + testRunCriteriaWithSources.AdapterSourceMap.ToList().ForEach(adapter => testRunCriteriaWithSources.AdapterSourceMap[adapter.Key] = UpdatePaths(adapter.Value, updateDirection)); var package = UpdatePath(testRunCriteriaWithSources.Package, updateDirection); return new TestRunCriteriaWithSources(testRunCriteriaWithSources.AdapterSourceMap, package, testRunCriteriaWithSources.RunSettings, testRunCriteriaWithSources.TestExecutionContext); } - public TestRunCriteriaWithTests UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests, PathConversionDirection updateDirection) + public TestRunCriteriaWithTests UpdateTestRunCriteriaWithTests(TestRunCriteriaWithTests testRunCriteriaWithTests!!, PathConversionDirection updateDirection) { var tests = UpdateTestCases(testRunCriteriaWithTests.Tests, updateDirection); var package = UpdatePath(testRunCriteriaWithTests.Package, updateDirection); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs index b10072231b..dea491e919 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs @@ -91,7 +91,7 @@ protected TestRequestHandler(IDataSerializer dataSerializer, ICommunicationEndpo _onLaunchAdapterProcessWithDebuggerAttachedAckReceived = (message) => throw new NotImplementedException(); _onAttachDebuggerAckRecieved = (message) => throw new NotImplementedException(); - _pathConverter = new NullPathConverter(); + _pathConverter = NullPathConverter.Instance; _jobQueue = new JobQueue( (action) => action(), "TestHostOperationQueue", @@ -107,14 +107,10 @@ public virtual void InitializeCommunication() { if (this is IDeploymentAwareTestRequestHandler self && !string.IsNullOrWhiteSpace(self.LocalPath) - && !string.IsNullOrEmpty(self.RemotePath)) + && !string.IsNullOrWhiteSpace(self.RemotePath)) { _pathConverter = new PathConverter(self.LocalPath, self.RemotePath, _fileHelper); } - else - { - _pathConverter = new NullPathConverter(); - } _communicationEndPoint = _communicationEndpointFactory.Create(ConnectionInfo.Role); _communicationEndPoint.Connected += (sender, connectedArgs) => diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs index b1f64f32b8..438a7048cd 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs @@ -29,4 +29,3 @@ [assembly: InternalsVisibleTo("vstest.console, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] -[assembly: InternalsVisibleTo("ConsoleApp1, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] From ee813794c46a55f03d98aa73dad5cfef14f31f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 16 Feb 2022 01:27:44 -0800 Subject: [PATCH 09/12] Update src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Amaury Levé --- .../EventHandlers/NullPathConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs index cb5ce19c44..2d375688a4 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/NullPathConverter.cs @@ -12,7 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; internal class NullPathConverter : IPathConverter { - private static readonly Lazy LazyInstance= new(() => new NullPathConverter()); + private static readonly Lazy LazyInstance = new(() => new NullPathConverter()); private NullPathConverter() { } From 08a1cdad29049282b230625ac108033fbc54520f Mon Sep 17 00:00:00 2001 From: nohwnd Date: Fri, 18 Feb 2022 17:44:45 +0100 Subject: [PATCH 10/12] Fix --- src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs index 438a7048cd..4b8057663a 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. + // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Runtime.CompilerServices; @@ -26,6 +26,15 @@ [assembly: InternalsVisibleTo("testhost.net471.x86, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("testhost.net472.x86, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("testhost.net48.x86, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.arm64, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net452.arm64, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net46.arm64, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net461.arm64, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net462.arm64, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net47.arm64, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net471.arm64, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net472.arm64, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("testhost.net48.arm64, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("vstest.console, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] From 22c61a66d4312a836f08fa72eed19a2eb68e9b30 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Fri, 18 Feb 2022 22:48:31 +0100 Subject: [PATCH 11/12] Fix assignment --- .../EventHandlers/TestRequestHandler.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs index 1af6675cc9..17a7f48661 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs @@ -78,7 +78,9 @@ protected TestRequestHandler( _onLaunchAdapterProcessWithDebuggerAttachedAckReceived = onLaunchAdapterProcessWithDebuggerAttachedAckReceived; _onAttachDebuggerAckRecieved = onAttachDebuggerAckRecieved; _jobQueue = jobQueue; + _fileHelper = new FileHelper(); + _pathConverter = NullPathConverter.Instance; } protected TestRequestHandler(IDataSerializer dataSerializer, ICommunicationEndpointFactory communicationEndpointFactory) @@ -91,7 +93,6 @@ protected TestRequestHandler(IDataSerializer dataSerializer, ICommunicationEndpo _onLaunchAdapterProcessWithDebuggerAttachedAckReceived = (message) => throw new NotImplementedException(); _onAttachDebuggerAckRecieved = (message) => throw new NotImplementedException(); - _pathConverter = NullPathConverter.Instance; _jobQueue = new JobQueue( (action) => action(), "TestHostOperationQueue", @@ -99,7 +100,9 @@ protected TestRequestHandler(IDataSerializer dataSerializer, ICommunicationEndpo 25000000, true, (message) => EqtTrace.Error(message)); + _fileHelper = new FileHelper(); + _pathConverter = NullPathConverter.Instance; } /// From caeaf22a99b3a7af3337d8eaa525f427ec3635c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Mon, 21 Feb 2022 11:01:10 +0100 Subject: [PATCH 12/12] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Amaury Levé --- .../EventHandlers/IPathConverter.cs | 3 ++- .../EventHandlers/PathConverter.cs | 5 +++-- src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs index 25519e89a4..3a310e8ca3 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/IPathConverter.cs @@ -4,10 +4,11 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using System.Collections.Generic; +using System.Collections.ObjectModel; + using ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; -using System.Collections.ObjectModel; internal interface IPathConverter { diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs index 6b7b1cdd33..7f02c971a6 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs @@ -4,13 +4,14 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; +using System.IO; + using ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; -using System.Collections.ObjectModel; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; -using System.IO; /// /// Converts paths in received and sent objects, to make testhost seem like it run a local test, diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs index 4b8057663a..0270330197 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Friends.cs @@ -1,4 +1,4 @@ - // Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Runtime.CompilerServices;