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 nullables on TestPlatform.Client #3745

Merged
merged 1 commit into from
Jun 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.Client.TestRunAttachmentsProcessing;

/// <summary>
/// The test run attachments processing events handler.
/// </summary>
///
///
public class TestRunAttachmentsProcessingEventsHandler : ITestRunAttachmentsProcessingEventsHandler
{
private readonly ICommunicationManager _communicationManager;
Expand All @@ -35,7 +33,7 @@ public void HandleTestRunAttachmentsProcessingComplete(TestRunAttachmentsProcess
{
EqtTrace.Info("Test run attachments processing completed.");

var payload = new TestRunAttachmentsProcessingCompletePayload()
var payload = new TestRunAttachmentsProcessingCompletePayload
{
AttachmentsProcessingCompleteEventArgs = attachmentsProcessingCompleteEventArgs,
Attachments = lastChunk
Expand Down
87 changes: 43 additions & 44 deletions src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Net;
using System.Threading;
Expand All @@ -26,8 +27,6 @@

using CommunicationUtilitiesResources = Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources.Resources;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode;

/// <summary>
Expand All @@ -45,9 +44,9 @@ public class DesignModeClient : IDesignModeClient
private readonly TestSessionMessageLogger _testSessionMessageLogger;
private readonly object _lockObject = new();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Part of the public API.")]
protected Action<Message> onCustomTestHostLaunchAckReceived;
protected Action<Message>? onCustomTestHostLaunchAckReceived;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Part of the public API.")]
protected Action<Message> onAttachDebuggerAckRecieved;
protected Action<Message>? onAttachDebuggerAckRecieved;

/// <summary>
/// Initializes a new instance of the <see cref="DesignModeClient"/> class.
Expand Down Expand Up @@ -81,11 +80,12 @@ internal DesignModeClient(ICommunicationManager communicationManager, IDataSeria
/// <summary>
/// Property exposing the Instance
/// </summary>
public static IDesignModeClient Instance { get; private set; }
public static IDesignModeClient? Instance { get; private set; }

/// <summary>
/// Initializes DesignMode
/// </summary>
[MemberNotNull(nameof(Instance))]
public static void Initialize()
{
Instance = new DesignModeClient();
Expand All @@ -102,7 +102,7 @@ public static void Initialize()
/// </param>
public void ConnectToClientAndProcessRequests(int port, ITestRequestManager testRequestManager)
{
EqtTrace.Info("Trying to connect to server on port : {0}", port);
EqtTrace.Info("Trying to connect to server on port: {0}", port);
_communicationManager.SetupClientAsync(new IPEndPoint(IPAddress.Loopback, port));

var connectionTimeoutInSecs = EnvironmentHelper.GetConnectionTimeout();
Expand All @@ -115,7 +115,7 @@ public void ConnectToClientAndProcessRequests(int port, ITestRequestManager test
}
else
{
EqtTrace.Error("DesignModeClient : ConnectToClientAndProcessRequests : Client timed out while connecting to the server.");
EqtTrace.Error("DesignModeClient.ConnectToClientAndProcessRequests: Client timed out while connecting to the server.");
Dispose();
throw new TimeoutException(
string.Format(
Expand All @@ -135,7 +135,7 @@ public void HandleParentProcessExit()
// this should end the "ProcessRequests" loop with an exception
Dispose();

EqtTrace.Info("DesignModeClient: Parent process exited, Exiting myself..");
EqtTrace.Info("DesignModeClient.HandleParentProcessExit: Parent process exited, Exiting myself...");

_platformEnvironment.Exit(1);
}
Expand Down Expand Up @@ -303,7 +303,7 @@ public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo, Cancellat
lock (_lockObject)
{
var waitHandle = new AutoResetEvent(false);
Message ackMessage = null;
Message? ackMessage = null;
onCustomTestHostLaunchAckReceived = (ackRawMessage) =>
{
ackMessage = ackRawMessage;
Expand Down Expand Up @@ -343,7 +343,7 @@ public bool AttachDebuggerToProcess(AttachDebuggerInfo attachDebuggerInfo, Cance
lock (_lockObject)
{
var waitHandle = new AutoResetEvent(false);
Message ackMessage = null;
Message? ackMessage = null;
onAttachDebuggerAckRecieved = (ackRawMessage) =>
{
ackMessage = ackRawMessage;
Expand All @@ -363,7 +363,7 @@ public bool AttachDebuggerToProcess(AttachDebuggerInfo attachDebuggerInfo, Cance
{
var payload = new EditorAttachDebuggerPayload
{
TargetFramework = attachDebuggerInfo.TargetFramework.ToString(),
TargetFramework = attachDebuggerInfo.TargetFramework?.ToString(),
ProcessID = attachDebuggerInfo.ProcessId,
};
_communicationManager.SendMessage(MessageType.EditorAttachDebugger2, payload);
Expand Down Expand Up @@ -394,7 +394,7 @@ public void SendRawMessage(string rawMessage)
}

/// <inheritdoc />
public void SendTestMessage(TestMessageLevel level, string message)
public void SendTestMessage(TestMessageLevel level, string? message)
{
var payload = new TestMessagePayload { MessageLevel = level, Message = message };
_communicationManager.SendMessage(MessageType.TestMessage, payload);
Expand All @@ -405,7 +405,7 @@ public void SendTestMessage(TestMessageLevel level, string message)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void TestRunMessageHandler(object sender, TestRunMessageEventArgs e)
public void TestRunMessageHandler(object? sender, TestRunMessageEventArgs e)
{
// save into trace log and send the message to the IDE
//
Expand Down Expand Up @@ -440,41 +440,40 @@ public void TestRunMessageHandler(object sender, TestRunMessageEventArgs e)

private void StartTestRun(TestRunRequestPayload testRunPayload, ITestRequestManager testRequestManager, bool shouldLaunchTesthost)
{
Task.Run(
() =>
Task.Run(() =>
{
try
{
try
{
testRequestManager.ResetOptions();
testRequestManager.ResetOptions();

// We must avoid re-launching the test host if the test run payload already
// 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
? DesignModeTestHostLauncherFactory.GetCustomHostLauncherForTestRun(
this,
testRunPayload.DebuggingEnabled)
: null;

testRequestManager.RunTests(testRunPayload, customLauncher, new DesignModeTestEventsRegistrar(this), _protocolConfig);
}
catch (Exception ex)
{
EqtTrace.Error("DesignModeClient: Exception in StartTestRun: " + ex);

// We must avoid re-launching the test host if the test run payload already
// 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
? DesignModeTestHostLauncherFactory.GetCustomHostLauncherForTestRun(
this,
testRunPayload.DebuggingEnabled)
: null;

testRequestManager.RunTests(testRunPayload, customLauncher, new DesignModeTestEventsRegistrar(this), _protocolConfig);
}
catch (Exception ex)
var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() };
_communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);
var runCompletePayload = new TestRunCompletePayload()
{
EqtTrace.Error("DesignModeClient: Exception in StartTestRun: " + ex);

var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() };
_communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);
var runCompletePayload = new TestRunCompletePayload()
{
TestRunCompleteArgs = new TestRunCompleteEventArgs(null, false, true, ex, null, null, TimeSpan.MinValue),
LastRunTests = null
};
TestRunCompleteArgs = new TestRunCompleteEventArgs(null, false, true, ex, null, null, TimeSpan.MinValue),
LastRunTests = null
};

// Send run complete to translation layer
_communicationManager.SendMessage(MessageType.ExecutionComplete, runCompletePayload);
}
});
// Send run complete to translation layer
_communicationManager.SendMessage(MessageType.ExecutionComplete, runCompletePayload);
}
});
}

private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITestRequestManager testRequestManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode;

/// <summary>
Expand Down Expand Up @@ -62,7 +58,7 @@ private void OnRawMessageReceived(object sender, string rawMessage)
_designModeClient.SendRawMessage(rawMessage);
}

public void LogWarning(string message)
public void LogWarning(string? message)
{
_designModeClient.SendTestMessage(TestMessageLevel.Warning, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode;

/// <summary>
/// Factory for providing the design mode test host launchers
/// </summary>
public static class DesignModeTestHostLauncherFactory
{
private static ITestHostLauncher3 s_defaultLauncher;
private static ITestHostLauncher3 s_debugLauncher;
private static ITestHostLauncher3? s_defaultLauncher;
private static ITestHostLauncher3? s_debugLauncher;

public static ITestHostLauncher3 GetCustomHostLauncherForTestRun(IDesignModeClient designModeClient, bool debuggingEnabled)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode;

/// <summary>
Expand Down Expand Up @@ -56,5 +54,5 @@ public interface IDesignModeClient : IDisposable
/// </summary>
/// <param name="level">Level for the message</param>
/// <param name="message">Actual message string</param>
void SendTestMessage(TestMessageLevel level, string message);
void SendTestMessage(TestMessageLevel level, string? message);
}
Loading