diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index 479ae048ec..c6a48b6bf0 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -218,7 +218,6 @@ private void ProcessRequests(ITestRequestManager testRequestManager) var testRunPayload = _communicationManager.DeserializePayload( message); - TPDebug.Assert(testRunPayload is not null, "testRunPayload is null"); StartTestRun(testRunPayload, testRequestManager, shouldLaunchTesthost: false); break; } @@ -227,7 +226,6 @@ private void ProcessRequests(ITestRequestManager testRequestManager) { var testRunAttachmentsProcessingPayload = _communicationManager.DeserializePayload(message); - TPDebug.Assert(testRunAttachmentsProcessingPayload is not null, "testRunAttachmentsProcessingPayload is null"); StartTestRunAttachmentsProcessing(testRunAttachmentsProcessingPayload, testRequestManager); break; } @@ -279,6 +277,10 @@ private void ProcessRequests(ITestRequestManager testRequestManager) default: { EqtTrace.Info("DesignModeClient: Invalid Message received: {0}", message); + if (message is null) + { + Stop(); + } break; } } @@ -286,11 +288,16 @@ private void ProcessRequests(ITestRequestManager testRequestManager) catch (Exception ex) { EqtTrace.Error("DesignModeClient: Error processing request: {0}", ex); - isSessionEnd = true; - Dispose(); + Stop(); } } while (!isSessionEnd); + + void Stop() + { + isSessionEnd = true; + Dispose(); + } } /// @@ -447,7 +454,7 @@ public void TestRunMessageHandler(object? sender, TestRunMessageEventArgs e) } } - private void StartTestRun(TestRunRequestPayload testRunPayload, ITestRequestManager testRequestManager, bool shouldLaunchTesthost) + private void StartTestRun(TestRunRequestPayload? testRunPayload, ITestRequestManager testRequestManager, bool shouldLaunchTesthost) { Task.Run(() => { @@ -459,13 +466,13 @@ private void StartTestRun(TestRunRequestPayload testRunPayload, ITestRequestMana // contains test session info. Test session info being present is an indicative // of an already running test host spawned by a start test session call. var customLauncher = - shouldLaunchTesthost && testRunPayload.TestSessionInfo == null + shouldLaunchTesthost && testRunPayload!.TestSessionInfo == null // TODO: Avoid throwing/catching NRE ? DesignModeTestHostLauncherFactory.GetCustomHostLauncherForTestRun( this, testRunPayload.DebuggingEnabled) : null; - testRequestManager.RunTests(testRunPayload, customLauncher, new DesignModeTestEventsRegistrar(this), _protocolConfig); + testRequestManager.RunTests(testRunPayload!, customLauncher, new DesignModeTestEventsRegistrar(this), _protocolConfig); } catch (Exception ex) { @@ -515,14 +522,15 @@ private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITe }); } - private void StartTestRunAttachmentsProcessing(TestRunAttachmentsProcessingPayload attachmentsProcessingPayload, ITestRequestManager testRequestManager) + private void StartTestRunAttachmentsProcessing(TestRunAttachmentsProcessingPayload? attachmentsProcessingPayload, ITestRequestManager testRequestManager) { Task.Run( () => { try { - testRequestManager.ProcessTestRunAttachments(attachmentsProcessingPayload, new TestRunAttachmentsProcessingEventsHandler(_communicationManager), _protocolConfig); + // TODO: Avoid throwing/catching NRE + testRequestManager.ProcessTestRunAttachments(attachmentsProcessingPayload!, new TestRunAttachmentsProcessingEventsHandler(_communicationManager), _protocolConfig); } catch (Exception ex) { diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Serialization/TestCaseConverter.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Serialization/TestCaseConverter.cs index f042d190fa..f0b3ddc0f1 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Serialization/TestCaseConverter.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Serialization/TestCaseConverter.cs @@ -58,14 +58,12 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } } - TPDebug.Assert(propertyData is not null, "propertyData is null"); - switch (testProperty.Id) { case "TestCase.Id": - testCase.Id = Guid.Parse(propertyData); break; + testCase.Id = Guid.Parse(propertyData!); break; case "TestCase.ExecutorUri": - testCase.ExecutorUri = new Uri(propertyData); break; + testCase.ExecutorUri = new Uri(propertyData!); break; case "TestCase.FullyQualifiedName": testCase.FullyQualifiedName = propertyData; break; case "TestCase.DisplayName": @@ -75,7 +73,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist case "TestCase.CodeFilePath": testCase.CodeFilePath = propertyData; break; case "TestCase.LineNumber": - testCase.LineNumber = int.Parse(propertyData); break; + testCase.LineNumber = int.Parse(propertyData!); break; default: // No need to register member properties as they get registered as part of TestCaseProperties class. testProperty = TestProperty.Register(testProperty.Id, testProperty.Label, testProperty.GetValueType(), testProperty.Attributes, typeof(TestObject)); diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Serialization/TestResultConverter.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Serialization/TestResultConverter.cs index 18ccb8ee71..1fa361fef8 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Serialization/TestResultConverter.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Serialization/TestResultConverter.cs @@ -85,7 +85,6 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } } - TPDebug.Assert(propertyData is not null, "propertyData is null"); switch (testProperty.Id) { case "TestResult.DisplayName": @@ -93,13 +92,13 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist case "TestResult.ComputerName": testResult.ComputerName = propertyData ?? string.Empty; break; case "TestResult.Outcome": - testResult.Outcome = (TestOutcome)Enum.Parse(typeof(TestOutcome), propertyData); break; + testResult.Outcome = (TestOutcome)Enum.Parse(typeof(TestOutcome), propertyData!); break; case "TestResult.Duration": - testResult.Duration = TimeSpan.Parse(propertyData); break; + testResult.Duration = TimeSpan.Parse(propertyData!); break; case "TestResult.StartTime": - testResult.StartTime = DateTimeOffset.Parse(propertyData); break; + testResult.StartTime = DateTimeOffset.Parse(propertyData!); break; case "TestResult.EndTime": - testResult.EndTime = DateTimeOffset.Parse(propertyData); break; + testResult.EndTime = DateTimeOffset.Parse(propertyData!); break; case "TestResult.ErrorMessage": testResult.ErrorMessage = propertyData; break; case "TestResult.ErrorStackTrace": diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs index d7dc481b39..abae753465 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs @@ -361,8 +361,13 @@ public void SendRawMessage(string rawMessage) { try { - TPDebug.Assert(_socket is not null, "_socket is null"); - if (_socket.Poll(STREAMREADTIMEOUT, SelectMode.SelectRead)) + if (_socket is null) + { + EqtTrace.Error("SocketCommunicationManager.TryReceiveRawMessage: Socket is null"); + break; + } + + if (_socket!.Poll(STREAMREADTIMEOUT, SelectMode.SelectRead) == true) { str = ReceiveRawMessage(); success = true; @@ -374,13 +379,13 @@ public void SendRawMessage(string rawMessage) && socketException.SocketErrorCode == SocketError.TimedOut) { EqtTrace.Info( - "SocketCommunicationManager ReceiveMessage: failed to receive message because read timeout {0}", + "SocketCommunicationManager.ReceiveMessage: failed to receive message because read timeout {0}", ioException); } else { EqtTrace.Error( - "SocketCommunicationManager ReceiveMessage: failed to receive message {0}", + "SocketCommunicationManager.ReceiveMessage: failed to receive message {0}", ioException); break; } @@ -388,7 +393,7 @@ public void SendRawMessage(string rawMessage) catch (Exception exception) { EqtTrace.Error( - "SocketCommunicationManager ReceiveMessage: failed to receive message {0}", + "SocketCommunicationManager.ReceiveMessage: failed to receive message {0}", exception); break; } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelDiscoveryEventsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelDiscoveryEventsHandler.cs index 4603f83c08..840aa59e07 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelDiscoveryEventsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelDiscoveryEventsHandler.cs @@ -7,7 +7,6 @@ using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; -using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Utilities; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscoveryManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscoveryManager.cs index 5f9307c9f7..d9e426d843 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscoveryManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscoveryManager.cs @@ -16,7 +16,6 @@ using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel; -using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Utilities; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; diff --git a/test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs index 2a2e7f8e3a..a6ae3672ca 100644 --- a/test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.IO; using System.Linq; using Microsoft.Extensions.FileSystemGlobbing;