Skip to content

Commit

Permalink
Fix warnings and failed assertions (#3767)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink authored Jun 16, 2022
1 parent 3f042dd commit f353f20
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 27 deletions.
26 changes: 17 additions & 9 deletions src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
var testRunPayload =
_communicationManager.DeserializePayload<TestRunRequestPayload>(
message);
TPDebug.Assert(testRunPayload is not null, "testRunPayload is null");
StartTestRun(testRunPayload, testRequestManager, shouldLaunchTesthost: false);
break;
}
Expand All @@ -227,7 +226,6 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
{
var testRunAttachmentsProcessingPayload =
_communicationManager.DeserializePayload<TestRunAttachmentsProcessingPayload>(message);
TPDebug.Assert(testRunAttachmentsProcessingPayload is not null, "testRunAttachmentsProcessingPayload is null");
StartTestRunAttachmentsProcessing(testRunAttachmentsProcessingPayload, testRequestManager);
break;
}
Expand Down Expand Up @@ -279,18 +277,27 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
default:
{
EqtTrace.Info("DesignModeClient: Invalid Message received: {0}", message);
if (message is null)
{
Stop();
}
break;
}
}
}
catch (Exception ex)
{
EqtTrace.Error("DesignModeClient: Error processing request: {0}", ex);
isSessionEnd = true;
Dispose();
Stop();
}
}
while (!isSessionEnd);

void Stop()
{
isSessionEnd = true;
Dispose();
}
}

/// <summary>
Expand Down Expand Up @@ -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(() =>
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,20 @@ 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":
testResult.DisplayName = propertyData; break;
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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -374,21 +379,21 @@ 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;
}
}
catch (Exception exception)
{
EqtTrace.Error(
"SocketCommunicationManager ReceiveMessage: failed to receive message {0}",
"SocketCommunicationManager.ReceiveMessage: failed to receive message {0}",
exception);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f353f20

Please sign in to comment.