Skip to content

Commit 7d5d972

Browse files
author
Rakeshwar Reddy Kambaiahgari
committed
Init commit
1 parent 182f2c4 commit 7d5d972

42 files changed

Lines changed: 7889 additions & 954 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/VirtualClient/VirtualClient.Actions.FunctionalTests/AspNetBenchProfileTests.cs

Lines changed: 111 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace VirtualClient.Actions
66
using System;
77
using System.Collections.Generic;
88
using System.Linq;
9+
using System.Net;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112
using NUnit.Framework;
@@ -17,19 +18,46 @@ namespace VirtualClient.Actions
1718
public class AspNetBenchProfileTests
1819
{
1920
private DependencyFixture mockFixture;
21+
private string clientAgentId;
22+
private string serverAgentId;
2023

2124
[OneTimeSetUp]
2225
public void SetupFixture()
2326
{
24-
this.mockFixture = new DependencyFixture();
27+
this.clientAgentId = $"{Environment.MachineName}-Client";
28+
this.serverAgentId = $"{Environment.MachineName}-Server";
29+
2530
ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory);
2631
}
2732

33+
[SetUp]
34+
public void Setup()
35+
{
36+
this.mockFixture = new DependencyFixture();
37+
}
38+
2839
[Test]
2940
[TestCase("PERF-ASPNETBENCH.json")]
3041
public void AspNetBenchWorkloadProfileParametersAreInlinedCorrectly(string profile)
3142
{
32-
this.mockFixture.Setup(PlatformID.Unix);
43+
this.mockFixture.Setup(PlatformID.Unix, agentId: this.clientAgentId).SetupLayout(
44+
new ClientInstance(this.clientAgentId, "1.2.3.5", ClientRole.Client),
45+
new ClientInstance(this.serverAgentId, "1.2.3.4", ClientRole.Server));
46+
47+
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
48+
{
49+
WorkloadAssert.ParameterReferencesInlined(executor.Profile);
50+
}
51+
}
52+
53+
[Test]
54+
[TestCase("PERF-ASPNETBENCH-AFFINITY.json")]
55+
public void AspNetBenchAffinityWorkloadProfileParametersAreInlinedCorrectly(string profile)
56+
{
57+
this.mockFixture.Setup(PlatformID.Unix, agentId: this.clientAgentId).SetupLayout(
58+
new ClientInstance(this.clientAgentId, "1.2.3.5", ClientRole.Client),
59+
new ClientInstance(this.serverAgentId, "1.2.3.4", ClientRole.Server));
60+
3361
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
3462
{
3563
WorkloadAssert.ParameterReferencesInlined(executor.Profile);
@@ -42,22 +70,41 @@ public async Task AspNetBenchWorkloadProfileExecutesTheExpectedWorkloadsOnWindow
4270
{
4371
IEnumerable<string> expectedCommands = this.GetProfileExpectedCommands(PlatformID.Win32NT);
4472
this.SetupDefaultMockBehaviors(PlatformID.Win32NT);
45-
// Setup the expectations for the workload
46-
// - Workload package is installed and exists.
47-
// - Workload binaries/executables exist on the file system.
48-
// - The workload generates valid results.
4973

5074
this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) =>
5175
{
5276
IProcessProxy process = this.mockFixture.CreateProcess(command, arguments, workingDir);
53-
if (arguments.Contains("bombardier", StringComparison.OrdinalIgnoreCase))
77+
78+
// Add bombardier results for any bombardier execution (with or without affinity)
79+
if (command.Contains("bombardier", StringComparison.OrdinalIgnoreCase) ||
80+
arguments.Contains("bombardier", StringComparison.OrdinalIgnoreCase))
5481
{
55-
process.StandardOutput.Append(TestDependencies.GetResourceFileContents("Results_AspNetBench.txt"));
82+
if (arguments.Contains("--version"))
83+
{
84+
process.StandardOutput.Append("bombardier version 1.2.5");
85+
}
86+
else
87+
{
88+
process.StandardOutput.Append(TestDependencies.GetResourceFileContents("Results_AspNetBench.txt"));
89+
}
5690
}
5791

5892
return process;
5993
};
6094

95+
// Setup API client for client-server communication
96+
this.SetupApiClient(this.serverAgentId, "1.2.3.4");
97+
98+
// Execute server actions
99+
this.mockFixture.SystemManagement.SetupGet(obj => obj.AgentId).Returns(this.serverAgentId);
100+
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
101+
{
102+
executor.ExecuteDependencies = false;
103+
await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None).ConfigureAwait(false);
104+
}
105+
106+
// Execute client actions
107+
this.mockFixture.SystemManagement.SetupGet(obj => obj.AgentId).Returns(this.clientAgentId);
61108
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
62109
{
63110
executor.ExecuteDependencies = false;
@@ -73,22 +120,41 @@ public async Task AspNetBenchWorkloadProfileExecutesTheExpectedWorkloadsOnUnixPl
73120
{
74121
IEnumerable<string> expectedCommands = this.GetProfileExpectedCommands(PlatformID.Unix);
75122
this.SetupDefaultMockBehaviors(PlatformID.Unix);
76-
// Setup the expectations for the workload
77-
// - Workload package is installed and exists.
78-
// - Workload binaries/executables exist on the file system.
79-
// - The workload generates valid results.
80123

81124
this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) =>
82125
{
83126
IProcessProxy process = this.mockFixture.CreateProcess(command, arguments, workingDir);
84-
if (arguments.Contains("bombardier", StringComparison.OrdinalIgnoreCase))
127+
128+
// Add bombardier results for any bombardier execution (with or without affinity)
129+
if (command.Contains("bombardier", StringComparison.OrdinalIgnoreCase) ||
130+
arguments.Contains("bombardier", StringComparison.OrdinalIgnoreCase))
85131
{
86-
process.StandardOutput.Append(TestDependencies.GetResourceFileContents("Results_AspNetBench.txt"));
132+
if (arguments.Contains("--version"))
133+
{
134+
process.StandardOutput.Append("bombardier version 1.2.5");
135+
}
136+
else
137+
{
138+
process.StandardOutput.Append(TestDependencies.GetResourceFileContents("Results_AspNetBench.txt"));
139+
}
87140
}
88141

89142
return process;
90143
};
91144

145+
// Setup API client for client-server communication
146+
this.SetupApiClient(this.serverAgentId, "1.2.3.4");
147+
148+
// Execute server actions
149+
this.mockFixture.SystemManagement.SetupGet(obj => obj.AgentId).Returns(this.serverAgentId);
150+
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
151+
{
152+
executor.ExecuteDependencies = false;
153+
await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None).ConfigureAwait(false);
154+
}
155+
156+
// Execute client actions
157+
this.mockFixture.SystemManagement.SetupGet(obj => obj.AgentId).Returns(this.clientAgentId);
92158
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
93159
{
94160
executor.ExecuteDependencies = false;
@@ -106,19 +172,23 @@ private IEnumerable<string> GetProfileExpectedCommands(PlatformID platform)
106172
case PlatformID.Win32NT:
107173
commands = new List<string>
108174
{
175+
@"pkill dotnet",
176+
@"fuser -n tcp -k 9876",
109177
@"dotnet\.exe build -c Release -p:BenchmarksTargetFramework=net8.0",
110-
@"dotnet\.exe .+Benchmarks.dll --nonInteractive true --scenarios json --urls http://localhost:9876 --server Kestrel --kestrelTransport Sockets --protocol http --header ""Accept:.+ keep-alive",
111-
@"bombardier\.exe --duration 15s --connections 256 --timeout 10s --fasthttp --insecure -l http://localhost:9876/json --print r --format json"
178+
@"dotnet\.exe .+Benchmarks\.dll --nonInteractive true --scenarios json --urls http://\*:9876 --server Kestrel --kestrelTransport Sockets --protocol http --header ""Accept:.+ keep-alive",
179+
@"bombardier\.exe --duration 15s --connections 256 --timeout 10s --fasthttp --insecure -l http://1\.2\.3\.4:9876/json --print r --format json"
112180
};
113181
break;
114182

115183
case PlatformID.Unix:
116184
commands = new List<string>
117185
{
118186
@"chmod \+x .+bombardier",
187+
@"pkill dotnet",
188+
@"fuser -n tcp -k 9876",
119189
@"dotnet build -c Release -p:BenchmarksTargetFramework=net8.0",
120-
@"dotnet .+Benchmarks.dll --nonInteractive true --scenarios json --urls http://localhost:9876 --server Kestrel --kestrelTransport Sockets --protocol http --header ""Accept:.+ keep-alive",
121-
@"bombardier --duration 15s --connections 256 --timeout 10s --fasthttp --insecure -l http://localhost:9876/json --print r --format json"
190+
@"dotnet .+Benchmarks\.dll --nonInteractive true --scenarios json --urls http://\*:9876 --server Kestrel --kestrelTransport Sockets --protocol http --header ""Accept:.+ keep-alive",
191+
@"bombardier --duration 15s --connections 256 --timeout 10s --fasthttp --insecure -l http://1\.2\.3\.4:9876/json --print r --format json"
122192
};
123193
break;
124194
}
@@ -130,21 +200,38 @@ private void SetupDefaultMockBehaviors(PlatformID platform)
130200
{
131201
if (platform == PlatformID.Win32NT)
132202
{
133-
this.mockFixture.Setup(PlatformID.Win32NT);
203+
this.mockFixture.Setup(PlatformID.Win32NT, agentId: this.clientAgentId).SetupLayout(
204+
new ClientInstance(this.clientAgentId, "1.2.3.5", ClientRole.Client),
205+
new ClientInstance(this.serverAgentId, "1.2.3.4", ClientRole.Server));
206+
134207
this.mockFixture.SetupPackage("aspnetbenchmarks", expectedFiles: @"aspnetbench");
135-
this.mockFixture.SetupPackage("bombardier", expectedFiles: @"win-x64\bombardier.exe");
136-
this.mockFixture.SetupPackage("dotnetsdk", expectedFiles: @"packages\dotnet\dotnet.exe");
208+
this.mockFixture.SetupPackage("bombardier", expectedFiles: @"bombardier.exe");
209+
this.mockFixture.SetupPackage("dotnetsdk", expectedFiles: @"dotnet.exe");
137210
}
138211
else
139212
{
140-
this.mockFixture.Setup(PlatformID.Unix);
213+
this.mockFixture.Setup(PlatformID.Unix, agentId: this.clientAgentId).SetupLayout(
214+
new ClientInstance(this.clientAgentId, "1.2.3.5", ClientRole.Client),
215+
new ClientInstance(this.serverAgentId, "1.2.3.4", ClientRole.Server));
141216

142217
this.mockFixture.SetupPackage("aspnetbenchmarks", expectedFiles: @"aspnetbench");
143-
this.mockFixture.SetupPackage("bombardier", expectedFiles: @"linux-x64\bombardier");
144-
this.mockFixture.SetupPackage("dotnetsdk", expectedFiles: @"packages\dotnet\dotnet");
218+
this.mockFixture.SetupPackage("bombardier", expectedFiles: @"bombardier");
219+
this.mockFixture.SetupPackage("dotnetsdk", expectedFiles: @"dotnet");
145220
}
146221

147222
this.mockFixture.SetupDisks(withRemoteDisks: false);
148223
}
224+
225+
private void SetupApiClient(string serverName, string serverIPAddress)
226+
{
227+
IPAddress.TryParse(serverIPAddress, out IPAddress ipAddress);
228+
IApiClient apiClient = this.mockFixture.ApiClientManager.GetOrCreateApiClient(serverName, ipAddress);
229+
230+
State state = new State();
231+
state.Online(true);
232+
233+
apiClient.CreateStateAsync(nameof(State), state, CancellationToken.None)
234+
.GetAwaiter().GetResult();
235+
}
149236
}
150237
}

0 commit comments

Comments
 (0)