Skip to content

Commit

Permalink
Enable nullable on remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Mar 22, 2022
1 parent 7aa51fc commit 72f2910
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 148 deletions.
Expand Up @@ -5,8 +5,6 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.PerformanceTests;

/// <summary>
Expand Down
Expand Up @@ -11,8 +11,6 @@

using TestResult = Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResult;

#nullable disable

namespace Microsoft.TestPlatform.PerformanceTests;

[TestClass]
Expand All @@ -30,7 +28,7 @@ public class ProtocolV1Tests
Traits = { new Trait("Priority", "0"), new Trait("Category", "unit") }
};

private static DateTimeOffset s_startTime = new(new DateTime(2007, 3, 10, 0, 0, 0, DateTimeKind.Utc));
private static readonly DateTimeOffset StartTime = new(new DateTime(2007, 3, 10, 0, 0, 0, DateTimeKind.Utc));

private static readonly TestResult TestResult = new(TestCase)
{
Expand All @@ -42,7 +40,7 @@ public class ProtocolV1Tests
DisplayName = "sampleTestResult",
ComputerName = "sampleComputerName",
Duration = TimeSpan.MaxValue,
StartTime = s_startTime,
StartTime = StartTime,
EndTime = DateTimeOffset.MaxValue
};

Expand Down
Expand Up @@ -11,8 +11,6 @@

using TestResult = Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResult;

#nullable disable

namespace Microsoft.TestPlatform.PerformanceTests;

[TestClass]
Expand Down
10 changes: 4 additions & 6 deletions test/Microsoft.TestPlatform.PerformanceTests/SocketTests.cs
Expand Up @@ -11,8 +11,6 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.PerformanceTests;

[TestClass]
Expand All @@ -25,8 +23,8 @@ public void SocketThroughput2()
// implementation.
var server = new SocketServer();
var client = new SocketClient();
ICommunicationChannel serverChannel = null;
ICommunicationChannel clientChannel = null;
ICommunicationChannel? serverChannel = null;
ICommunicationChannel? clientChannel = null;
ManualResetEventSlim dataTransferred = new(false);
ManualResetEventSlim clientConnected = new(false);
ManualResetEventSlim serverConnected = new(false);
Expand Down Expand Up @@ -104,7 +102,7 @@ public void SocketThroughput1()
Assert.IsTrue(watch.Elapsed < TimeSpan.FromSeconds(4), "Elapsed: " + watch.Elapsed);
}

private static void SendData(ICommunicationChannel channel, Stopwatch watch)
private static void SendData(ICommunicationChannel? channel, Stopwatch watch)
{
var dataBytes = new byte[65536];
for (int i = 0; i < dataBytes.Length; i++)
Expand All @@ -117,7 +115,7 @@ private static void SendData(ICommunicationChannel channel, Stopwatch watch)
watch.Start();
for (int i = 0; i < 20000; i++)
{
channel.Send(dataBytesStr);
channel!.Send(dataBytesStr);
}
}

Expand Down
Expand Up @@ -7,8 +7,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.PerformanceTests.TranslationLayer;

[TestClass]
Expand Down
Expand Up @@ -7,8 +7,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

#nullable disable

namespace Microsoft.TestPlatform.PerformanceTests.TranslationLayer;

/// <inheritdoc />
Expand All @@ -22,7 +20,7 @@ public class DiscoveryEventHandler2 : ITestDiscoveryEventsHandler2
/// <summary>
/// Gets the metrics.
/// </summary>
public IDictionary<string, object> Metrics { get; private set; }
public IDictionary<string, object>? Metrics { get; private set; }

public DiscoveryEventHandler2()
{
Expand Down
Expand Up @@ -7,8 +7,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

#nullable disable

namespace Microsoft.TestPlatform.PerformanceTests.TranslationLayer;

/// <inheritdoc />
Expand All @@ -22,12 +20,12 @@ public class RunEventHandler : ITestRunEventsHandler2
/// <summary>
/// Gets the metrics.
/// </summary>
public IDictionary<string, object> Metrics { get; private set; }
public IDictionary<string, object>? Metrics { get; private set; }

/// <summary>
/// Gets the log message.
/// </summary>
public string LogMessage { get; private set; }
public string? LogMessage { get; private set; }

/// <summary>
/// Gets the test message level.
Expand Down
Expand Up @@ -7,15 +7,13 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.PerformanceTests.TranslationLayer;

[TestClass]
public class ExecutionPerfTests : TelemetryPerfTestbase
{
private IVsTestConsoleWrapper _vstestConsoleWrapper;
private RunEventHandler _runEventHandler;
private readonly IVsTestConsoleWrapper _vstestConsoleWrapper;
private readonly RunEventHandler _runEventHandler;

public ExecutionPerfTests()
{
Expand Down
Expand Up @@ -12,16 +12,14 @@
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.PerformanceTests.TranslationLayer;

[TestClass]
public class TelemetryPerfTestbase
{
private const string TelemetryInstrumentationKey = "76b373ba-8a55-45dd-b6db-7f1a83288691";
private readonly TelemetryClient _client;
private readonly DirectoryInfo _currentDirectory = new DirectoryInfo(typeof(DiscoveryPerfTests).GetTypeInfo().Assembly.GetAssemblyLocation()).Parent;
private readonly DirectoryInfo _currentDirectory = new DirectoryInfo(typeof(DiscoveryPerfTests).GetTypeInfo().Assembly.GetAssemblyLocation()).Parent!;

public TelemetryPerfTestbase()
{
Expand All @@ -34,21 +32,24 @@ public TelemetryPerfTestbase()
/// </summary>
/// <param name="perfScenario"></param>
/// <param name="handlerMetrics"></param>
public void PostTelemetry(string perfScenario, IDictionary<string, object> handlerMetrics)
public void PostTelemetry(string perfScenario, IDictionary<string, object>? handlerMetrics)
{
var properties = new Dictionary<string, string>();
var properties = new Dictionary<string, string?>();
var metrics = new Dictionary<string, double>();

foreach (var entry in handlerMetrics)
if (handlerMetrics is not null)
{
var stringValue = entry.Value.ToString();
if (double.TryParse(stringValue, out var doubleValue))
{
metrics.Add(entry.Key, doubleValue);
}
else
foreach (var entry in handlerMetrics)
{
properties.Add(entry.Key, stringValue);
var stringValue = entry.Value.ToString();
if (double.TryParse(stringValue, out var doubleValue))
{
metrics.Add(entry.Key, doubleValue);
}
else
{
properties.Add(entry.Key, stringValue);
}
}
}
_client.TrackEvent(perfScenario, properties, metrics);
Expand Down Expand Up @@ -93,7 +94,7 @@ private string BuildConfiguration
private string GetConsoleRunnerPath()
{
// Find the root
var root = _currentDirectory.Parent.Parent.Parent;
var root = _currentDirectory.Parent!.Parent!.Parent!;
// Path to artifacts vstest.console
return Path.Combine(root.FullName, BuildConfiguration, "net451", "win7-x64", "vstest.console.exe");
}
Expand Down
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -27,8 +28,6 @@

using Moq;

#nullable disable

namespace TestPlatform.TestHostProvider.Hosting.UnitTests;

[TestClass]
Expand All @@ -40,10 +39,10 @@ public class DefaultTestHostManagerTests
private readonly Mock<IFileHelper> _mockFileHelper;
private readonly Mock<IDotnetHostHelper> _mockDotnetHostHelper;
private readonly Mock<IEnvironment> _mockEnvironment;

private readonly DefaultTestHostManager _testHostManager;
private TestableTestHostManager _testableTestHostManager;
private string _errorMessage;

private TestableTestHostManager? _testableTestHostManager;
private string? _errorMessage;
private int _exitCode;
private int _testHostId;

Expand Down Expand Up @@ -404,17 +403,17 @@ public void LaunchTestHostShouldSetExitCallbackInCaseCustomHost()
[TestCategory("Windows")]
public void GetTestSourcesShouldReturnAppropriateSourceIfAppxRecipeIsProvided()
{
var sourcePath = Path.Combine(Path.GetDirectoryName(typeof(TestableTestHostManager).GetTypeInfo().Assembly.GetAssemblyLocation()), @"..\..\..\..\TestAssets\UWPTestAssets\UnitTestApp8.build.appxrecipe");
var sourcePath = Path.Combine(Path.GetDirectoryName(typeof(TestableTestHostManager).GetTypeInfo().Assembly.GetAssemblyLocation())!, @"..\..\..\..\TestAssets\UWPTestAssets\UnitTestApp8.build.appxrecipe");
IEnumerable<string> sources = _testHostManager.GetTestSources(new List<string> { sourcePath });
Assert.IsTrue(sources.Any());
Assert.IsTrue(sources.FirstOrDefault().EndsWith(".exe", StringComparison.OrdinalIgnoreCase));
Assert.IsTrue(sources.First().EndsWith(".exe", StringComparison.OrdinalIgnoreCase));
}

[TestMethod]
[TestCategory("Windows")]
public void AppxManifestFileShouldReturnAppropriateSourceIfAppxManifestIsProvided()
{
var appxManifestPath = Path.Combine(Path.GetDirectoryName(typeof(TestableTestHostManager).GetTypeInfo().Assembly.GetAssemblyLocation()), @"..\..\..\..\TestAssets\UWPTestAssets\AppxManifest.xml");
var appxManifestPath = Path.Combine(Path.GetDirectoryName(typeof(TestableTestHostManager).GetTypeInfo().Assembly.GetAssemblyLocation())!, @"..\..\..\..\TestAssets\UWPTestAssets\AppxManifest.xml");
string source = AppxManifestFile.GetApplicationExecutableName(appxManifestPath);
Assert.AreEqual("UnitTestApp8.exe", source);
}
Expand Down Expand Up @@ -495,25 +494,26 @@ public async Task CleanTestHostAsyncShouldNotThrowIfTestHostIsNotStarted()
Assert.IsTrue(isVerified);
}

private void TestableTestHostManagerHostExited(object sender, HostProviderEventArgs e)
private void TestableTestHostManagerHostExited(object? sender, HostProviderEventArgs e)
{
_errorMessage = e.Data.TrimEnd(Environment.NewLine.ToCharArray());
_exitCode = e.ErrroCode;
}

private void TestHostManagerHostExited(object sender, HostProviderEventArgs e)
private void TestHostManagerHostExited(object? sender, HostProviderEventArgs e)
{
if (e.ErrroCode != 0)
{
_errorMessage = e.Data.TrimEnd(Environment.NewLine.ToCharArray());
}
}

private void TestHostManagerHostLaunched(object sender, HostProviderEventArgs e)
private void TestHostManagerHostLaunched(object? sender, HostProviderEventArgs e)
{
_testHostId = e.ProcessId;
}

[MemberNotNull(nameof(_testableTestHostManager))]
private void ErrorCallBackTestHelper(string errorMessage, int exitCode)
{
_testableTestHostManager = new TestableTestHostManager(
Expand Down Expand Up @@ -547,6 +547,7 @@ private void ErrorCallBackTestHelper(string errorMessage, int exitCode)
_mockProcessHelper.Setup(ph => ph.TryGetExitCode(It.IsAny<object>(), out exitCode)).Returns(true);
}

[MemberNotNull(nameof(_testableTestHostManager))]
private void ExitCallBackTestHelper(int exitCode)
{
_testableTestHostManager = new TestableTestHostManager(
Expand Down Expand Up @@ -578,7 +579,7 @@ private void ExitCallBackTestHelper(int exitCode)
_mockProcessHelper.Setup(ph => ph.TryGetExitCode(It.IsAny<object>(), out exitCode)).Returns(true);
}

private TestProcessStartInfo GetDefaultStartInfo()
private static TestProcessStartInfo GetDefaultStartInfo()
{
return new TestProcessStartInfo();
}
Expand Down

0 comments on commit 72f2910

Please sign in to comment.