Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable nullable on Communication utilities #3758

Merged
merged 4 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper;
using Microsoft.VisualStudio.TestPlatform.Client.TestRunAttachmentsProcessing;
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.Logging;
using Microsoft.VisualStudio.TestPlatform.Common.Utilities;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
Expand Down Expand Up @@ -158,7 +159,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager)

EqtTrace.Info("DesignModeClient.ProcessRequests: Processing Message: {0}", message);

switch (message.MessageType)
switch (message?.MessageType)
{
case MessageType.VersionCheck:
{
Expand All @@ -179,20 +180,23 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
case MessageType.StartTestSession:
{
var testSessionPayload = _communicationManager.DeserializePayload<StartTestSessionPayload>(message);
TPDebug.Assert(testSessionPayload is not null, "testSessionPayload is null");
StartTestSession(testSessionPayload, testRequestManager);
break;
}

case MessageType.StopTestSession:
{
var testSessionPayload = _communicationManager.DeserializePayload<StopTestSessionPayload>(message);
TPDebug.Assert(testSessionPayload is not null, "testSessionPayload is null");
StopTestSession(testSessionPayload, testRequestManager);
break;
}

case MessageType.StartDiscovery:
{
var discoveryPayload = _dataSerializer.DeserializePayload<DiscoveryRequestPayload>(message);
TPDebug.Assert(discoveryPayload is not null, "discoveryPayload is null");
StartDiscovery(discoveryPayload, testRequestManager);
break;
}
Expand All @@ -203,6 +207,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
var testRunPayload =
_communicationManager.DeserializePayload<TestRunRequestPayload>(
message);
TPDebug.Assert(testRunPayload is not null, "testRunPayload is null");
StartTestRun(testRunPayload, testRequestManager, shouldLaunchTesthost: true);
break;
}
Expand All @@ -213,6 +218,7 @@ 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 @@ -221,6 +227,7 @@ 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 @@ -323,7 +330,9 @@ public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo, Cancellat

onCustomTestHostLaunchAckReceived = null;

TPDebug.Assert(ackMessage is not null, "ackMessage is null");
var ackPayload = _dataSerializer.DeserializePayload<CustomHostLaunchAckPayload>(ackMessage);
TPDebug.Assert(ackPayload is not null, "ackPayload is null");

return ackPayload.HostProcessId > 0 ? ackPayload.HostProcessId : throw new TestPlatformException(ackPayload.ErrorMessage);
}
Expand All @@ -344,7 +353,7 @@ public bool AttachDebuggerToProcess(AttachDebuggerInfo attachDebuggerInfo, Cance
{
var waitHandle = new AutoResetEvent(false);
Message? ackMessage = null;
onAttachDebuggerAckRecieved = (ackRawMessage) =>
onAttachDebuggerAckRecieved = ackRawMessage =>
{
ackMessage = ackRawMessage;
waitHandle.Set();
Expand All @@ -355,9 +364,7 @@ public bool AttachDebuggerToProcess(AttachDebuggerInfo attachDebuggerInfo, Cance
// a type of T as well to prevent some more mistakes.
if (_protocolConfig.Version < 7)
{
#pragma warning disable CS0618 // Type or member is obsolete
_communicationManager.SendMessage(MessageType.EditorAttachDebugger, attachDebuggerInfo.ProcessId, _protocolConfig.Version);
#pragma warning restore CS0618 // Type or member is obsolete
}
else
{
Expand All @@ -374,7 +381,9 @@ public bool AttachDebuggerToProcess(AttachDebuggerInfo attachDebuggerInfo, Cance
cancellationToken.ThrowTestPlatformExceptionIfCancellationRequested();
onAttachDebuggerAckRecieved = null;

TPDebug.Assert(ackMessage is not null, "ackMessage is null");
var ackPayload = _dataSerializer.DeserializePayload<EditorAttachDebuggerAckPayload>(ackMessage);
TPDebug.Assert(ackPayload is not null, "ackPayload is null");
if (!ackPayload.Attached)
{
EqtTrace.Warning($"DesignModeClient.AttachDebuggerToProcess: Attaching to process failed: {ackPayload.ErrorMessage}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public void HandleRawMessage(string rawMessage)

if (string.Equals(message?.MessageType, MessageType.DiscoveryComplete))
{
var discoveryCompletePayload = _dataSerializer.DeserializePayload<DiscoveryCompletePayload>(message);
var discoveryCompletePayload = _dataSerializer.DeserializePayload<DiscoveryCompletePayload>(message!);
rawMessage = UpdateRawMessageWithTelemetryInfo(discoveryCompletePayload, message) ?? rawMessage;
HandleLoggerManagerDiscoveryComplete(discoveryCompletePayload);
}
Expand All @@ -376,7 +376,7 @@ public void HandleRawMessage(string rawMessage)
/// Handles LoggerManager's DiscoveryComplete.
/// </summary>
/// <param name="discoveryCompletePayload">Discovery complete payload.</param>
private void HandleLoggerManagerDiscoveryComplete(DiscoveryCompletePayload discoveryCompletePayload)
private void HandleLoggerManagerDiscoveryComplete(DiscoveryCompletePayload? discoveryCompletePayload)
{
if (LoggerManager.LoggersInitialized && discoveryCompletePayload != null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public void HandleRawMessage(string rawMessage)

if (string.Equals(message?.MessageType, MessageType.ExecutionComplete))
{
var testRunCompletePayload = _dataSerializer.DeserializePayload<TestRunCompletePayload>(message);
var testRunCompletePayload = _dataSerializer.DeserializePayload<TestRunCompletePayload>(message!);
rawMessage = UpdateRawMessageWithTelemetryInfo(testRunCompletePayload, message) ?? rawMessage;
HandleLoggerManagerTestRunComplete(testRunCompletePayload);
}
Expand All @@ -549,7 +549,7 @@ public void HandleRawMessage(string rawMessage)
/// Handles LoggerManager's TestRunComplete.
/// </summary>
/// <param name="testRunCompletePayload">TestRun complete payload.</param>
private void HandleLoggerManagerTestRunComplete(TestRunCompletePayload testRunCompletePayload)
private void HandleLoggerManagerTestRunComplete(TestRunCompletePayload? testRunCompletePayload)
{
if (!LoggerManager.LoggersInitialized || testRunCompletePayload == null)
{
Expand All @@ -567,7 +567,7 @@ private void HandleLoggerManagerTestRunComplete(TestRunCompletePayload testRunCo
// Send test run complete to logger manager.
TestRunCompleteEventArgs testRunCompleteArgs =
new(
testRunCompletePayload.TestRunCompleteArgs.TestRunStatistics,
testRunCompletePayload.TestRunCompleteArgs!.TestRunStatistics,
testRunCompletePayload.TestRunCompleteArgs.IsCanceled,
testRunCompletePayload.TestRunCompleteArgs.IsAborted,
testRunCompletePayload.TestRunCompleteArgs.Error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Microsoft.VisualStudio.TestPlatform.Client.RequestHelper.ITestRequestManager.Can
Microsoft.VisualStudio.TestPlatform.Client.RequestHelper.ITestRequestManager.CancelTestRun() -> void
Microsoft.VisualStudio.TestPlatform.Client.RequestHelper.ITestRequestManager.CancelTestRunAttachmentsProcessing() -> void
Microsoft.VisualStudio.TestPlatform.Client.RequestHelper.ITestRequestManager.DiscoverTests(Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.DiscoveryRequestPayload! discoveryPayload, Microsoft.VisualStudio.TestPlatform.Common.Interfaces.ITestDiscoveryEventsRegistrar! disoveryEventsRegistrar, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ProtocolConfig! protocolConfig) -> void
Microsoft.VisualStudio.TestPlatform.Client.RequestHelper.ITestRequestManager.InitializeExtensions(System.Collections.Generic.IEnumerable<string!>! pathToAdditionalExtensions, bool skipExtensionFilters) -> void
Microsoft.VisualStudio.TestPlatform.Client.RequestHelper.ITestRequestManager.InitializeExtensions(System.Collections.Generic.IEnumerable<string!>? pathToAdditionalExtensions, bool skipExtensionFilters) -> void
Microsoft.VisualStudio.TestPlatform.Client.RequestHelper.ITestRequestManager.ProcessTestRunAttachments(Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestRunAttachmentsProcessingPayload! testRunAttachmentsProcessingPayload, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ITestRunAttachmentsProcessingEventsHandler! testRunAttachmentsProcessingEventsHandler, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ProtocolConfig! protocolConfig) -> void
Microsoft.VisualStudio.TestPlatform.Client.RequestHelper.ITestRequestManager.ResetOptions() -> void
Microsoft.VisualStudio.TestPlatform.Client.TestPlatformFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface ITestRequestManager : IDisposable
/// <param name="pathToAdditionalExtensions">Paths to additional extensions.</param>
/// <param name="skipExtensionFilters">Skip extension filtering by name if true.</param>
void InitializeExtensions(
IEnumerable<string> pathToAdditionalExtensions,
IEnumerable<string>? pathToAdditionalExtensions,
bool skipExtensionFilters);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void Dispose()

/// <inheritdoc/>
public void UpdateExtensions(
IEnumerable<string> pathToAdditionalExtensions,
IEnumerable<string>? pathToAdditionalExtensions,
bool skipExtensionFilters)
{
_testEngine.GetExtensionManager().UseAdditionalExtensions(pathToAdditionalExtensions, skipExtensionFilters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
using CommunicationUtilitiesResources = Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources.Resources;
using CoreUtilitiesConstants = Microsoft.VisualStudio.TestPlatform.CoreUtilities.Constants;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection;

/// <summary>
Expand All @@ -43,21 +41,15 @@ internal class DataCollectionRequestHandler : IDataCollectionRequestHandler, IDi
private static readonly object SyncObject = new();

private readonly ICommunicationManager _communicationManager;

private readonly IMessageSink _messageSink;

private readonly IDataCollectionManager _dataCollectionManager;

private readonly IDataCollectionTestCaseEventHandler _dataCollectionTestCaseEventHandler;

private Task _testCaseEventMonitorTask;

private readonly IDataSerializer _dataSerializer;

private readonly IFileHelper _fileHelper;

private readonly IRequestData _requestData;

private Task? _testCaseEventMonitorTask;

/// <summary>
/// Use to cancel data collection test case events monitoring if test run is canceled.
/// </summary>
Expand Down Expand Up @@ -131,7 +123,7 @@ protected DataCollectionRequestHandler(
/// <summary>
/// Gets the singleton instance of DataCollectionRequestHandler.
/// </summary>
public static DataCollectionRequestHandler Instance { get; private set; }
public static DataCollectionRequestHandler? Instance { get; private set; }

/// <summary>
/// Creates singleton instance of DataCollectionRequestHandler.
Expand Down Expand Up @@ -208,7 +200,7 @@ public void ProcessRequests()

EqtTrace.Info("DataCollectionRequestHandler.ProcessRequests: Datacollector received message: {0}", message);

switch (message.MessageType)
switch (message?.MessageType)
{
case MessageType.BeforeTestRunStart:
HandleBeforeTestRunStart(message);
Expand All @@ -221,11 +213,12 @@ public void ProcessRequests()

case MessageType.TestHostLaunched:
var testHostLaunchedPayload = _dataSerializer.DeserializePayload<TestHostLaunchedPayload>(message);
TPDebug.Assert(testHostLaunchedPayload is not null, "testHostLaunchedPayload is null");
_dataCollectionManager.TestHostLaunched(testHostLaunchedPayload.ProcessId);
break;

default:
EqtTrace.Error("DataCollectionRequestHandler.ProcessRequests : Invalid Message types: {0}", message.MessageType);
EqtTrace.Error("DataCollectionRequestHandler.ProcessRequests : Invalid Message types: {0}", message?.MessageType);
break;
}
}
Expand Down Expand Up @@ -270,16 +263,23 @@ private void AddExtensionAssemblies(BeforeTestRunStartPayload payload)
{
try
{
var customTestAdaptersPaths = RunSettingsUtilities.GetTestAdaptersPaths(payload.SettingsXml);
TPDebug.Assert(payload is not null, "payload is null");

if (payload.Sources is null)
{
EqtTrace.Verbose("DataCollectionRequestHandler.AddExtensionAssemblies: No sources provided");
return;
}

// In case of dotnet vstest with code coverage, data collector needs to be picked up from publish folder.
// Therefore, adding source dll folders to search datacollectors in these.
var datacollectorSearchPaths = new HashSet<string>();
foreach (var source in payload.Sources)
{
datacollectorSearchPaths.Add(Path.GetDirectoryName(source));
datacollectorSearchPaths.Add(Path.GetDirectoryName(source)!);
}

var customTestAdaptersPaths = RunSettingsUtilities.GetTestAdaptersPaths(payload.SettingsXml);
if (customTestAdaptersPaths != null)
{
datacollectorSearchPaths.UnionWith(customTestAdaptersPaths);
Expand Down Expand Up @@ -319,12 +319,13 @@ private void HandleBeforeTestRunStart(Message message)
{
// Initialize datacollectors and get environment variables.
var payload = _dataSerializer.DeserializePayload<BeforeTestRunStartPayload>(message);
TPDebug.Assert(payload is not null, "payload is null");
UpdateRequestData(payload.IsTelemetryOptedIn);
AddExtensionAssemblies(payload);

var envVariables = _dataCollectionManager.InitializeDataCollectors(payload.SettingsXml);

var properties = new Dictionary<string, object>
var properties = new Dictionary<string, object?>
{
{ CoreUtilitiesConstants.TestSourcesKeyName, payload.Sources }
};
Expand Down
Loading