Skip to content
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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.1
3.3.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace VirtualClient.Actions
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using VirtualClient;
using VirtualClient.Common.Telemetry;
using VirtualClient.Contracts;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using NUnit.Framework;

[TestFixture]
[Category("Unit")]
[Platform(Exclude = "Unix,Linux,MacOsX")]
public class DotNetRuntimeExecutorTests
{
private MockFixture fixture;
private DependencyPath mockPath;
private DependencyPath currentDirectoryPath;
private string rawString;

[SetUp]
public void SetUpTests()
{
this.fixture = new MockFixture();
this.fixture.Setup(PlatformID.Win32NT);
this.mockPath = this.fixture.Create<DependencyPath>();
this.fixture.Parameters = new Dictionary<string, IConvertible>
{
{ "PackageName", "DotNetRuntime" }
};

this.SetupDefaultMockBehavior();
}

[Test]
public async Task DotNetRuntimeExecutorInitializesItsDependenciesAsExpected()
{
using (TestDotNetRuntimeExecutor executor = new TestDotNetRuntimeExecutor(this.fixture))
{
Assert.IsNull(executor.ExecutablePath);

await executor.InitializeAsync(EventContext.None, CancellationToken.None)
.ConfigureAwait(false);

string expectedPath = this.fixture.PlatformSpecifics.Combine(
this.mockPath.Path, "win-x64", "dotnet.bat");
Assert.AreEqual(expectedPath, executor.ExecutablePath);
}
}

[Test]
public void DotNetRuntimeExecutorThrowsOnInitializationWhenTheWorkloadPackageIsNotFound()
{
this.fixture.PackageManager.OnGetPackage().ReturnsAsync(null as DependencyPath);
using (TestDotNetRuntimeExecutor executor = new TestDotNetRuntimeExecutor(this.fixture))
{
DependencyException exception = Assert.ThrowsAsync<DependencyException>(
() => executor.InitializeAsync(EventContext.None, CancellationToken.None));
Assert.AreEqual(ErrorReason.WorkloadDependencyMissing, exception.Reason);
}
}

[Test]
[Ignore("There is some kind of very unusual and difficult to determine anomaly that causes this method to fail to run due to a call to the IProcessProxy.Kill() method downstream.")]
public async Task DotNetRuntimeExecutorExecutesWorkloadAsExpected()
{
using (TestDotNetRuntimeExecutor executor = new TestDotNetRuntimeExecutor(this.fixture))
{
string expectedFilePath = this.fixture.PlatformSpecifics.Combine(this.mockPath.Path, "runtimes", "win-x64", "dotnet.bat");
int executed = 0;
this.fixture.ProcessManager.OnCreateProcess = (file, arguments, workingDirectory) =>
{
executed++;
Assert.AreEqual(expectedFilePath, file);
return this.fixture.Process;
};

await executor.ExecuteAsync(EventContext.None, CancellationToken.None)
.ConfigureAwait(false);

Assert.AreEqual(1, executed);
}
}

[Test]
[Ignore("There is some kind of very unusual and difficult to determine anomaly that causes this method to fail to run due to a call to the IProcessProxy.Kill() method downstream.")]
public void DotNetRuntimeExecutorThrowsWorkloadExceptionWhenTheResultsFileIsNotGenerated()
{
using (TestDotNetRuntimeExecutor executor = new TestDotNetRuntimeExecutor(this.fixture))
{
this.fixture.ProcessManager.OnCreateProcess = (file, arguments, workingDirectory) =>
{
this.fixture.FileSystem.Setup(fe => fe.File.Exists(executor.ResultsFilePath)).Returns(false);
return this.fixture.Process;
};

WorkloadException exception = Assert.ThrowsAsync<WorkloadException>(
() => executor.ExecuteAsync(EventContext.None, CancellationToken.None));
Assert.AreEqual(ErrorReason.WorkloadFailed, exception.Reason);
}
}

private void SetupDefaultMockBehavior()
{
string currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
this.currentDirectoryPath = new DependencyPath("DotNetRuntime", currentDirectory);
string resultsPath = this.fixture.PlatformSpecifics.Combine(this.currentDirectoryPath.Path, "Examples", "DotNetRuntimeResultsExample.txt");
this.rawString = File.ReadAllText(resultsPath);
this.fixture.FileSystem.Setup(fe => fe.File.Exists(It.IsAny<string>())).Returns(true);
this.fixture.FileSystem.Setup(fe => fe.File.Exists(null)).Returns(false);
this.fixture.FileSystem.Setup(fc => fc.File.Copy(It.IsAny<string>(), It.IsAny<string>()));
this.fixture.Directory.Setup(d => d.Exists(It.IsAny<string>()))
.Returns(true);

this.fixture.FileSystem.Setup(rt => rt.File.ReadAllTextAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(this.rawString);

this.fixture.PackageManager.OnGetPackage().ReturnsAsync(this.mockPath);
this.fixture.ProcessManager.OnCreateProcess = (command, arguments, directory) => this.fixture.Process;
}

private class TestDotNetRuntimeExecutor : DotNetRuntimeExecutor
{
public TestDotNetRuntimeExecutor(MockFixture fixture)
: base(fixture.Dependencies, fixture.Parameters)
{
}

public TestDotNetRuntimeExecutor(IServiceCollection dependencies, IDictionary<string, IConvertible> parameters)
: base(dependencies, parameters)
{
}

public new Task InitializeAsync(EventContext telemetryContext, CancellationToken cancellationToken)
{
return base.InitializeAsync(telemetryContext, cancellationToken);
}

public new Task ExecuteAsync(EventContext context, CancellationToken cancellationToken)
{
this.InitializeAsync(context, cancellationToken).GetAwaiter().GetResult();
return base.ExecuteAsync(context, cancellationToken);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using VirtualClient.Contracts;
using NUnit.Framework;
using VirtualClient;

namespace VirtualClient.Actions
{

[TestFixture]
[Category("Unit")]
internal class DotNetRuntimeMetricsParserUnitTests
{
private string rawText;
private DotNetRuntimeMetricsParser testParser;

[SetUp]
public void Setup()
{
string workingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string outputPath = Path.Combine(workingDirectory, @"Examples", "DotNetRuntimeResultsExample.txt");
this.rawText = File.ReadAllText(outputPath);
this.testParser = new DotNetRuntimeMetricsParser(this.rawText);
}

[Test]
public void DotNetRuntimeParserVerifyThroughputResult()
{
this.testParser.Parse();
this.testParser.ThroughputResult.PrintDataTableFormatted();
Assert.AreEqual(4, this.testParser.ThroughputResult.Columns.Count);
}

[Test]
public void DotNetRuntimeParserVerifyMetrics()
{
IList<Metric> metrics = this.testParser.Parse();
MetricAssert.Exists(metrics, "throughput", 11284.51, "bops");
}

[Test]
public void DotNetRuntimeParserThrowIfInvalidOutputFormat()
{
string workingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string IncorrectDotNetoutputPath =Path.Combine(workingDirectory, @"Examples", "IncorrectDotNetRuntimeResultsExample.txt");
this.rawText = File.ReadAllText(IncorrectDotNetoutputPath);
this.testParser = new DotNetRuntimeMetricsParser(this.rawText);
SchemaException exception = Assert.Throws<SchemaException>(() => this.testParser.Parse());
StringAssert.Contains("The DotNetRuntime output file has incorrect format for parsing", exception.Message);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
===============================================================================
TOTALS FOR: COMPANY with 8 warehouses
........ .NET fixed throughput benchmark 1.0 Results (time in seconds) ........
Count Total Min Max Avg Heap Space
New Order: 9142643 4568.99 0.000 ****** 0.000 total 0.0MB
Payment: 6101520 2572.06 0.000 ****** 0.000 used 0.0MB
OrderStatus: 691503 368.25 0.000 39.781 0.001
Delivery: 671169 3068.53 0.000 ****** 0.005
Stock Level: 671171 693.12 0.000 79.547 0.001
Cust Report: 3060386 1945.34 0.000 ****** 0.001

throughput = 11284.51 bops
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is IncorrectDotNetRuntime example.
Loading
Loading