Skip to content

Commit baa054f

Browse files
author
Rakeshwar Reddy Kambaiahgari
committed
commit changes
1 parent e0610a6 commit baa054f

9 files changed

Lines changed: 774 additions & 335 deletions

File tree

src/VirtualClient/VirtualClient.Actions.FunctionalTests/Redis/RedisClientProfileTests.cs

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace VirtualClient.Actions
88
using System.Linq;
99
using System.Net;
1010
using System.Runtime.InteropServices;
11+
using System.Text.RegularExpressions;
1112
using System.Threading;
1213
using System.Threading.Tasks;
1314
using NUnit.Framework;
@@ -36,7 +37,9 @@ public void SetupFixture()
3637
new ClientInstance(this.clientAgentId, "1.2.3.4", "Client"),
3738
new ClientInstance(this.serverAgentId, "1.2.3.5", "Server"));
3839

39-
this.mockFixture.SetupPackage("wget", expectedFiles: "linux-x64/wget2");
40+
this.mockFixture.SetupPackage("wget", null, "linux-x64/wget2");
41+
this.mockFixture.SetupPackage("redis", null, "src/redis-benchmark", "src/redis-server");
42+
this.mockFixture.SetupPackage("memtier", null, "memtier_benchmark");
4043
}
4144

4245
[Test]
@@ -53,46 +56,26 @@ public void RedisMemtierWorkloadProfileActionsWillNotBeExecutedIfTheClientWorklo
5356
}
5457

5558
[Test]
56-
[Ignore("We need to completely refactor the functional tests for Memcached and Redis to consolidate and cleanup.")]
5759
[TestCase("PERF-REDIS.json")]
5860
public async Task RedisMemtierWorkloadProfileExecutesTheWorkloadAsExpectedOfClientOnUnixPlatform(string profile)
5961
{
60-
IEnumerable<string> expectedCommands = new List<string>
61-
{
62-
$"--protocol redis --clients 1 --threads 4 --ratio 1:9 --data-size 32 --pipeline 32 --key-minimum 1 --key-maximum 10000000 --key-pattern R:R --run-count 1 --test-time 180 --print-percentile 50,90,95,99,99.9 --random-data",
63-
$" -h 1.2.3.5 -p 6379 -c 1 -n 10000 -P 32 -q --csv\""
64-
};
65-
66-
// Setup the expectations for the workload
67-
// - Workload package is installed and exists.
68-
// - Workload binaries/executables exist on the file system.
69-
// - Expected processes are executed.
70-
this.mockFixture.SetupFile(@"/home/user/tools/VirtualClient/scripts/Redis/RunClient.sh");
71-
this.mockFixture.SetupFile(@"/home/user/tools/VirtualClient/packages/redis-6.2.1/src/redis-benchmark");
62+
this.mockFixture
63+
.TrackProcesses()
64+
.SetupProcessOutput(
65+
"memtier_benchmark.*--server",
66+
TestDependencies.GetResourceFileContents("Results_RedisMemtier.txt"));
7267

7368
this.SetupApiClient(this.serverAgentId, serverIPAddress: "1.2.3.5");
7469

75-
this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) =>
76-
{
77-
IProcessProxy process = this.mockFixture.CreateProcess(command, arguments, workingDir);
78-
79-
if (arguments.Contains("memtier_benchmark --server", StringComparison.OrdinalIgnoreCase))
80-
{
81-
process.StandardOutput.Append(TestDependencies.GetResourceFileContents("Results_RedisMemtier.txt"));
82-
}
83-
else if (arguments.Contains("redis-benchmark", StringComparison.OrdinalIgnoreCase))
84-
{
85-
process.StandardOutput.Append(TestDependencies.GetResourceFileContents("Results_RedisBenchmark.txt"));
86-
}
87-
88-
return process;
89-
};
90-
9170
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
9271
{
9372
await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None)
9473
.ConfigureAwait(false);
95-
WorkloadAssert.CommandsExecuted(this.mockFixture, expectedCommands.ToArray());
74+
75+
this.mockFixture.Tracking.AssertCommandsExecuted(
76+
"sudo chmod \\+x.*memtier_benchmark",
77+
"memtier_benchmark.*--server 1\\.2\\.3\\.5.*--port 6379.*--protocol redis",
78+
"memtier_benchmark.*--server 1\\.2\\.3\\.5.*--port 6380.*--protocol redis");
9679
}
9780
}
9881

src/VirtualClient/VirtualClient.Actions.FunctionalTests/Redis/RedisServerProfileTests.cs

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace VirtualClient.Actions
88
using System.Linq;
99
using System.Net;
1010
using System.Runtime.InteropServices;
11-
using System.Text;
11+
using System.Text.RegularExpressions;
1212
using System.Threading;
1313
using System.Threading.Tasks;
1414
using Moq;
@@ -35,7 +35,7 @@ public void SetupFixture()
3535

3636
ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory);
3737

38-
this.mockFixture.SetupPackage("wget", expectedFiles: "linux-x64/wget2");
38+
this.mockFixture.SetupPackage("wget", null, "linux-x64/wget2");
3939
this.mockFixture.SetupFile("redis", "redis-6.2.1/src/redis-server", new byte[0]);
4040
this.mockFixture.SystemManagement.Setup(mgr => mgr.GetCpuInfoAsync(It.IsAny<CancellationToken>()))
4141
.ReturnsAsync(new CpuInfo("AnyName", "AnyDescription", 1, 4, 1, 0, true));
@@ -45,48 +45,33 @@ public void SetupFixture()
4545
[TestCase("PERF-REDIS.json")]
4646
public async Task RedisMemtierWorkloadProfileInstallsTheExpectedDependenciesOfServerOnUnixPlatform(string profile)
4747
{
48-
using var memoryProcess = new InMemoryProcess
49-
{
50-
StandardOutput = new ConcurrentBuffer(
51-
new StringBuilder("Redis server v=7.0.15 sha=00000000 malloc=jemalloc-5.1.0 bits=64 build=abc123")),
52-
OnStart = () => true,
53-
OnHasExited = () => true
54-
};
55-
56-
this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) =>
57-
{
58-
IProcessProxy process = this.mockFixture.CreateProcess(command, arguments, workingDir);
59-
if (arguments?.Contains("redis-server") == true && arguments?.Contains("--version") == true)
60-
{
61-
return memoryProcess;
62-
}
48+
this.mockFixture
49+
.TrackProcesses()
50+
.SetupProcessOutput(
51+
"redis-server.*--version",
52+
"Redis server v=7.0.15 sha=00000000 malloc=jemalloc-5.1.0 bits=64 build=abc123");
6353

64-
return process;
65-
};
6654
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
6755
{
6856
await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None)
6957
.ConfigureAwait(false);
7058

71-
// Workload dependency package expectations
7259
WorkloadAssert.WorkloadPackageInstalled(this.mockFixture, "redis");
60+
61+
this.mockFixture.Tracking.AssertCommandsExecuted("redis-server.*--version");
7362
}
7463
}
7564

7665
[Test]
7766
[TestCase("PERF-REDIS.json")]
7867
public async Task RedisMemtierWorkloadProfileExecutesTheWorkloadAsExpectedOfServerOnUnixPlatformMultiVM(string profile)
7968
{
80-
List<string> expectedCommands = new List<string>();
81-
82-
int port = 6379;
83-
Enumerable.Range(0, 4).ToList().ForEach(core =>
84-
expectedCommands.Add($"sudo bash -c \"numactl -C {core} /.+/redis-server --port {port + core} --protected-mode no --io-threads 4 --maxmemory-policy noeviction --ignore-warnings ARM64-COW-BUG --save &\""));
69+
this.mockFixture
70+
.TrackProcesses()
71+
.SetupProcessOutput(
72+
"redis-server.*--version",
73+
"Redis server v=7.0.15 sha=00000000 malloc=jemalloc-5.1.0 bits=64 build=abc123");
8574

86-
// Setup the expectations for the workload
87-
// - Workload package is installed and exists.
88-
// - Workload binaries/executables exist on the file system.
89-
// - Expected processes are executed.
9075
IPAddress.TryParse("1.2.3.5", out IPAddress ipAddress);
9176
IApiClient apiClient = this.mockFixture.ApiClientManager.GetOrCreateApiClient("1.2.3.5", ipAddress);
9277

@@ -105,29 +90,20 @@ public async Task RedisMemtierWorkloadProfileExecutesTheWorkloadAsExpectedOfServ
10590
});
10691

10792
await apiClient.CreateStateAsync(nameof(ServerState), state, CancellationToken.None);
108-
using var memoryProcess = new InMemoryProcess
109-
{
110-
StandardOutput = new ConcurrentBuffer(
111-
new StringBuilder("Redis server v=7.0.15 sha=00000000 malloc=jemalloc-5.1.0 bits=64 build=abc123")),
112-
OnStart = () => true,
113-
OnHasExited = () => true
114-
};
115-
116-
this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) =>
117-
{
118-
IProcessProxy process = this.mockFixture.CreateProcess(command, arguments, workingDir);
119-
if (arguments?.Contains("redis-server") == true && arguments?.Contains("--version") == true)
120-
{
121-
return memoryProcess;
122-
}
123-
124-
return process;
125-
};
12693

12794
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
12895
{
12996
await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None);
130-
WorkloadAssert.CommandsExecuted(this.mockFixture, expectedCommands.ToArray());
97+
98+
this.mockFixture.Tracking.AssertCommandsExecutedInOrder(
99+
$"sudo chmod \\+x.*redis-server",
100+
$"sudo bash -c \\\"numactl -C 0.*redis-server --port 6379.*\\\"",
101+
$"sudo bash -c \\\"numactl -C 1.*redis-server --port 6380.*\\\"",
102+
$"sudo bash -c \\\"numactl -C 2.*redis-server --port 6381.*\\\"",
103+
$"sudo bash -c \\\"numactl -C 3.*redis-server --port 6382.*\\\"");
104+
105+
this.mockFixture.Tracking.AssertCommandExecutedTimes("chmod.*redis-server", 1);
106+
this.mockFixture.Tracking.AssertCommandExecutedTimes("numactl.*redis-server", 4);
131107
}
132108
}
133109
}

0 commit comments

Comments
 (0)