Skip to content
Open
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 @@ -6,6 +6,7 @@ namespace VirtualClient.Actions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
Expand All @@ -17,19 +18,32 @@ namespace VirtualClient.Actions
public class AspNetBenchProfileTests
{
private DependencyFixture mockFixture;
private string clientAgentId;
private string serverAgentId;

[OneTimeSetUp]
public void SetupFixture()
{
this.mockFixture = new DependencyFixture();
this.clientAgentId = $"{Environment.MachineName}-Client";
this.serverAgentId = $"{Environment.MachineName}-Server";

ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory);
}

[SetUp]
public void Setup()
{
this.mockFixture = new DependencyFixture();
}

[Test]
[TestCase("PERF-ASPNETBENCH.json")]
public void AspNetBenchWorkloadProfileParametersAreInlinedCorrectly(string profile)
{
this.mockFixture.Setup(PlatformID.Unix);
this.mockFixture.Setup(PlatformID.Unix, agentId: this.clientAgentId).SetupLayout(
new ClientInstance(this.clientAgentId, "1.2.3.5", ClientRole.Client),
new ClientInstance(this.serverAgentId, "1.2.3.4", ClientRole.Server));

using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
{
WorkloadAssert.ParameterReferencesInlined(executor.Profile);
Expand All @@ -42,10 +56,6 @@ public async Task AspNetBenchWorkloadProfileExecutesTheExpectedWorkloadsOnWindow
{
IEnumerable<string> expectedCommands = this.GetProfileExpectedCommands(PlatformID.Win32NT);
this.SetupDefaultMockBehaviors(PlatformID.Win32NT);
// Setup the expectations for the workload
// - Workload package is installed and exists.
// - Workload binaries/executables exist on the file system.
// - The workload generates valid results.

this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) =>
{
Expand All @@ -58,6 +68,9 @@ public async Task AspNetBenchWorkloadProfileExecutesTheExpectedWorkloadsOnWindow
return process;
};

// Setup API client for client-server communication
this.SetupApiClient(this.serverAgentId, "1.2.3.4");

using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
{
executor.ExecuteDependencies = false;
Expand All @@ -73,10 +86,6 @@ public async Task AspNetBenchWorkloadProfileExecutesTheExpectedWorkloadsOnUnixPl
{
IEnumerable<string> expectedCommands = this.GetProfileExpectedCommands(PlatformID.Unix);
this.SetupDefaultMockBehaviors(PlatformID.Unix);
// Setup the expectations for the workload
// - Workload package is installed and exists.
// - Workload binaries/executables exist on the file system.
// - The workload generates valid results.

this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) =>
{
Expand All @@ -89,6 +98,9 @@ public async Task AspNetBenchWorkloadProfileExecutesTheExpectedWorkloadsOnUnixPl
return process;
};

// Setup API client for client-server communication
this.SetupApiClient(this.serverAgentId, "1.2.3.4");

using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
{
executor.ExecuteDependencies = false;
Expand All @@ -107,8 +119,10 @@ private IEnumerable<string> GetProfileExpectedCommands(PlatformID platform)
commands = new List<string>
{
@"dotnet\.exe build -c Release -p:BenchmarksTargetFramework=net8.0",
@"dotnet\.exe .+Benchmarks.dll --nonInteractive true --scenarios json --urls http://localhost:9876 --server Kestrel --kestrelTransport Sockets --protocol http --header ""Accept:.+ keep-alive",
@"bombardier\.exe --duration 15s --connections 256 --timeout 10s --fasthttp --insecure -l http://localhost:9876/json --print r --format json"
@"pkill dotnet",
@"fuser -n tcp -k 9876",
@"dotnet\.exe .+Benchmarks.dll --nonInteractive true --scenarios json --urls http://\*:9876 --server Kestrel --kestrelTransport Sockets --protocol http --header ""Accept:.+ keep-alive",
@"bombardier\.exe --duration 15s --connections 256 --timeout 10s --fasthttp --insecure -l http://1\.2\.3\.4:9876/json --print r --format json"
};
break;

Expand All @@ -117,8 +131,10 @@ private IEnumerable<string> GetProfileExpectedCommands(PlatformID platform)
{
@"chmod \+x .+bombardier",
@"dotnet build -c Release -p:BenchmarksTargetFramework=net8.0",
@"dotnet .+Benchmarks.dll --nonInteractive true --scenarios json --urls http://localhost:9876 --server Kestrel --kestrelTransport Sockets --protocol http --header ""Accept:.+ keep-alive",
@"bombardier --duration 15s --connections 256 --timeout 10s --fasthttp --insecure -l http://localhost:9876/json --print r --format json"
@"pkill dotnet",
@"fuser -n tcp -k 9876",
@"dotnet .+Benchmarks.dll --nonInteractive true --scenarios json --urls http://\*:9876 --server Kestrel --kestrelTransport Sockets --protocol http --header ""Accept:.+ keep-alive",
@"bombardier --duration 15s --connections 256 --timeout 10s --fasthttp --insecure -l http://1\.2\.3\.4:9876/json --print r --format json"
};
break;
}
Expand All @@ -130,14 +146,19 @@ private void SetupDefaultMockBehaviors(PlatformID platform)
{
if (platform == PlatformID.Win32NT)
{
this.mockFixture.Setup(PlatformID.Win32NT);
this.mockFixture.Setup(PlatformID.Win32NT, agentId: this.clientAgentId).SetupLayout(
new ClientInstance(this.clientAgentId, "1.2.3.5", ClientRole.Client),
new ClientInstance(this.serverAgentId, "1.2.3.4", ClientRole.Server));

this.mockFixture.SetupPackage("aspnetbenchmarks", expectedFiles: @"aspnetbench");
this.mockFixture.SetupPackage("bombardier", expectedFiles: @"win-x64\bombardier.exe");
this.mockFixture.SetupPackage("dotnetsdk", expectedFiles: @"packages\dotnet\dotnet.exe");
}
else
{
this.mockFixture.Setup(PlatformID.Unix);
this.mockFixture.Setup(PlatformID.Unix, agentId: this.clientAgentId).SetupLayout(
new ClientInstance(this.clientAgentId, "1.2.3.5", ClientRole.Client),
new ClientInstance(this.serverAgentId, "1.2.3.4", ClientRole.Server));

this.mockFixture.SetupPackage("aspnetbenchmarks", expectedFiles: @"aspnetbench");
this.mockFixture.SetupPackage("bombardier", expectedFiles: @"linux-x64\bombardier");
Expand All @@ -146,5 +167,17 @@ private void SetupDefaultMockBehaviors(PlatformID platform)

this.mockFixture.SetupDisks(withRemoteDisks: false);
}

private void SetupApiClient(string serverName, string serverIPAddress)
{
IPAddress.TryParse(serverIPAddress, out IPAddress ipAddress);
IApiClient apiClient = this.mockFixture.ApiClientManager.GetOrCreateApiClient(serverName, ipAddress);

State state = new State();
state.Online(true);

apiClient.CreateStateAsync(nameof(State), state, CancellationToken.None)
.GetAwaiter().GetResult();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace VirtualClient.Actions
{
using System;
using System.Collections.Generic;
using NUnit.Framework;
using VirtualClient.Contracts;

[TestFixture]
[Category("Functional")]
public class NginxWrkProfileTests
{
private DependencyFixture mockFixture;

[OneTimeSetUp]
public void SetupFixture()
{
this.mockFixture = new DependencyFixture();
ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory);
}

[Test]
[TestCase("PERF-WEB-NGINX-WRK.json")]
[TestCase("PERF-WEB-NGINX-WRK2.json")]
public void NginxWrkProfileParametersAreInlinedCorrectly(string profile)
{
this.mockFixture.Setup(PlatformID.Unix);
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
{
WorkloadAssert.ParameterReferencesInlined(executor.Profile);
}
}

[Test]
[TestCase("PERF-WEB-NGINX-WRK.json")]
[TestCase("PERF-WEB-NGINX-WRK2.json")]
public void NginxWrkProfileParametersAreAvailable(string profile)
{
this.mockFixture.Setup(PlatformID.Unix);

var serverPrams = new List<string> { "PackageName", "Role", "Timeout" };

var reverseProxyPrams = new List<string> { "PackageName", "Role", "Timeout" };

var clientPrams = new List<string> { "PackageName", "Role", "Timeout", "TestDuration", "FileSizeInKB", "Connection", "ThreadCount", "CommandArguments", "MetricScenario", "Scenario" };

using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
{
foreach (var actionBlock in executor.Profile.Actions)
{
string role = actionBlock.Parameters["Role"].ToString();

if (role.Equals("server", StringComparison.OrdinalIgnoreCase))
{
foreach (var pram in serverPrams)
{
if (!actionBlock.Parameters.ContainsKey(pram))
{
Assert.False(true, $"{actionBlock.Type} does not have {pram} parameter.");
}
}
}
else if (role.Equals("reverseproxy", StringComparison.OrdinalIgnoreCase))
{
foreach (var pram in reverseProxyPrams)
{
if (!actionBlock.Parameters.ContainsKey(pram))
{
Assert.False(true, $"{actionBlock.Type} does not have {pram} parameter.");
}
}
}
else
{
foreach (var pram in clientPrams)
{
if (!actionBlock.Parameters.ContainsKey(pram))
{
Assert.False(true, $"{actionBlock.Type} does not have {pram} parameter.");
}
}
}
}
}
}
}
}
Loading