Skip to content

Commit 1b0ddd6

Browse files
authored
[Event Hubs] Stress Tests Updates (#34044)
* upgrading * adding test scenario interface * finished test scenario migrate * fixing template * dockerfile fix * switching to properties
1 parent 48fcf08 commit 1b0ddd6

File tree

15 files changed

+269
-318
lines changed

15 files changed

+269
-318
lines changed

sdk/eventhub/Azure.Messaging.EventHubs/stress/Chart.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ description: Stress tests for Event Hubs for .NET
55

66
dependencies:
77
- name: stress-test-addons
8-
version: 0.1.20
8+
version: 0.2.0
99
repository: https://stresstestcharts.blob.core.windows.net/helm/
1010

1111
annotations:
1212
stressTest: 'true'
1313
namespace: 'net'
14-
dockerbuilddir: '../../../..'
15-
dockerfile: './Dockerfile'

sdk/eventhub/Azure.Messaging.EventHubs/stress/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:6.0-cbl-mariner1.0 AS build-env
1+
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
22

33
# Copy in engineering system needed to build
44
COPY ./eng/ /app/eng/
@@ -23,9 +23,9 @@ RUN dotnet build './sdk/eventhub/Azure.Messaging.EventHubs/stress/src/' --config
2323
# Copy in the dll files to be ready to run
2424
FROM build-env as publish
2525
WORKDIR /app
26-
COPY --from=build-env /app/artifacts/bin/Azure.Messaging.EventHubs.Stress/Release/net6.0/ /app/artifacts/bin/Azure.Messaging.EventHubs.Stress/Release/net6.0/
26+
COPY --from=build-env /app/artifacts/bin/Azure.Messaging.EventHubs.Stress/Release/net7.0/ /app/artifacts/bin/Azure.Messaging.EventHubs.Stress/Release/net7.0/
2727

28-
WORKDIR /app/artifacts/bin/Azure.Messaging.EventHubs.Stress/Release/net6.0
28+
WORKDIR /app/artifacts/bin/Azure.Messaging.EventHubs.Stress/Release/net7.0
2929

3030
# The default is running just the "EventProducerTest"
3131
ENTRYPOINT ["dotnet Azure.Messaging.EventHubs.Stress.dll", "--test"]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
scenarios:
2+
- scenarioName: Consumer
3+
imageBuildDir: ../../../..
4+
Scenario: consumer
5+
image: Dockerfile
6+
imageTag: stresspgs7b6dif73rup6.azurecr.io/mredding/eventhub-net-stress/dockerfile:mredding
7+
- scenarioName: EventProd
8+
imageBuildDir: ../../../..
9+
Scenario: eventprod
10+
image: Dockerfile
11+
imageTag: stresspgs7b6dif73rup6.azurecr.io/mredding/eventhub-net-stress/dockerfile:mredding
12+
- scenarioName: BuffProd
13+
imageBuildDir: ../../../..
14+
Scenario: buffprod
15+
image: Dockerfile
16+
imageTag: stresspgs7b6dif73rup6.azurecr.io/mredding/eventhub-net-stress/dockerfile:mredding
17+
- scenarioName: BurstBuffProd
18+
imageBuildDir: ../../../..
19+
Scenario: burstbuffprod
20+
image: Dockerfile
21+
imageTag: stresspgs7b6dif73rup6.azurecr.io/mredding/eventhub-net-stress/dockerfile:mredding
22+
- scenarioName: Processor
23+
imageBuildDir: ../../../..
24+
Scenario: processor
25+
image: Dockerfile
26+
imageTag: stresspgs7b6dif73rup6.azurecr.io/mredding/eventhub-net-stress/dockerfile:mredding
27+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
matrix:
2+
scenarios:
3+
consumer:
4+
image: Dockerfile
5+
imageBuildDir: "../../../.."
6+
scenarioName: "Consumer"
7+
eventprod:
8+
image: Dockerfile
9+
imageBuildDir: "../../../.."
10+
scenarioName: "EventProd"
11+
buffprod:
12+
image: Dockerfile
13+
imageBuildDir: "../../../.."
14+
scenarioName: "BuffProd"
15+
burstbuffprod:
16+
image: Dockerfile
17+
imageBuildDir: "../../../.."
18+
scenarioName: "BurstBuffProd"
19+
processor:
20+
image: Dockerfile
21+
imageBuildDir: "../../../.."
22+
scenarioName: "Processor"

sdk/eventhub/Azure.Messaging.EventHubs/stress/src/Program.cs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ private static async Task RunOptions(Options opts)
5959
// test scenario runs are run in parallel.
6060

6161
var testScenarioTasks = new List<Task>();
62-
var testsToRun = opts.All ? Enum.GetValues(typeof(TestScenario)) : new TestScenario[]{StringToTestScenario(opts.Test)};
62+
var testsToRun = opts.All ? Enum.GetValues(typeof(TestScenarioName)) : new TestScenarioName[]{StringToTestScenario(opts.Test)};
6363

6464
var testParameters = new TestParameters();
6565
testParameters.EventHubsConnectionString = eventHubsConnectionString;
66+
var runAllRoles = !int.TryParse(opts.Role, out var roleIndex);
67+
testParameters.JobIndex = roleIndex;
68+
testParameters.RunAllRoles = runAllRoles;
6669

6770
var cancellationSource = new CancellationTokenSource();
6871
var runDuration = TimeSpan.FromHours(testParameters.DurationInHours);
@@ -74,7 +77,7 @@ private static async Task RunOptions(Options opts)
7477

7578
try
7679
{
77-
foreach (TestScenario testScenario in testsToRun)
80+
foreach (TestScenarioName testScenario in testsToRun)
7881
{
7982
var testName = testScenario.ToString();
8083
metrics.Client.Context.GlobalProperties["TestName"] = testName;
@@ -86,31 +89,31 @@ private static async Task RunOptions(Options opts)
8689

8790
switch (testScenario)
8891
{
89-
case TestScenario.BufferedProducerTest:
92+
case TestScenarioName.BufferedProducerTest:
9093
environment.TryGetValue(EnvironmentVariables.EventHubBufferedProducerTest, out eventHubName);
9194
testParameters.EventHub = PromptForResources("Event Hub", testName, eventHubName, opts.Interactive);
9295

93-
var bufferedProducerTest = new BufferedProducerTest(testParameters, metrics, opts.Role);
96+
var bufferedProducerTest = new BufferedProducerTest(testParameters, metrics);
9497
testScenarioTasks.Add(bufferedProducerTest.RunTestAsync(cancellationSource.Token));
9598
break;
9699

97-
case TestScenario.BurstBufferedProducerTest:
100+
case TestScenarioName.BurstBufferedProducerTest:
98101
environment.TryGetValue(EnvironmentVariables.EventHubBurstBufferedProducerTest, out eventHubName);
99102
testParameters.EventHub = PromptForResources("Event Hub", testName, eventHubName, opts.Interactive);
100103

101-
var burstBufferedProducerTest = new BurstBufferedProducerTest(testParameters, metrics, opts.Role);
104+
var burstBufferedProducerTest = new BurstBufferedProducerTest(testParameters, metrics);
102105
testScenarioTasks.Add(burstBufferedProducerTest.RunTestAsync(cancellationSource.Token));
103106
break;
104107

105-
case TestScenario.EventProducerTest:
108+
case TestScenarioName.EventProducerTest:
106109
environment.TryGetValue(EnvironmentVariables.EventHubEventProducerTest, out eventHubName);
107110
testParameters.EventHub = PromptForResources("Event Hub", testName, eventHubName, opts.Interactive);
108111

109-
var eventProducerTest = new EventProducerTest(testParameters, metrics, opts.Role);
112+
var eventProducerTest = new EventProducerTest(testParameters, metrics);
110113
testScenarioTasks.Add(eventProducerTest.RunTestAsync(cancellationSource.Token));
111114
break;
112115

113-
case TestScenario.ProcessorTest:
116+
case TestScenarioName.ProcessorTest:
114117
// Get the Event Hub name for this test
115118
environment.TryGetValue(EnvironmentVariables.EventHubProcessorTest, out eventHubName);
116119
testParameters.EventHub = PromptForResources("Event Hub", testName, eventHubName, opts.Interactive);
@@ -123,15 +126,15 @@ private static async Task RunOptions(Options opts)
123126
environment.TryGetValue(EnvironmentVariables.StorageAccountProcessorTest, out storageConnectionString);
124127
testParameters.StorageConnectionString = PromptForResources("Storage Account Connection String", testName, storageConnectionString, opts.Interactive);
125128

126-
var processorTest = new ProcessorTest(testParameters, metrics, opts.Role);
129+
var processorTest = new ProcessorTest(testParameters, metrics);
127130
testScenarioTasks.Add(processorTest.RunTestAsync(cancellationSource.Token));
128131
break;
129132

130-
case TestScenario.ConsumerTest:
133+
case TestScenarioName.ConsumerTest:
131134
environment.TryGetValue(EnvironmentVariables.EventHubBurstBufferedProducerTest, out eventHubName);
132135
testParameters.EventHub = PromptForResources("Event Hub", testName, eventHubName, opts.Interactive);
133136

134-
var consumerTest = new ConsumerTest(testParameters, metrics, opts.Role);
137+
var consumerTest = new ConsumerTest(testParameters, metrics);
135138
testScenarioTasks.Add(consumerTest.RunTestAsync(cancellationSource.Token));
136139
break;
137140
}
@@ -175,20 +178,20 @@ private static async Task RunOptions(Options opts)
175178
}
176179

177180
/// <summary>
178-
/// Converts a string into a <see cref="TestScenario"/> value.
181+
/// Converts a string into a <see cref="TestScenarioName"/> value.
179182
/// </summary>
180183
///
181-
/// <param name="testScenario">The string to convert to a <see cref="TestScenario"/>.</param>
184+
/// <param name="testScenario">The string to convert to a <see cref="TestScenarioName"/>.</param>
182185
///
183-
/// <returns>The <see cref="TestScenario"/> of the string input.</returns>
186+
/// <returns>The <see cref="TestScenarioName"/> of the string input.</returns>
184187
///
185-
public static TestScenario StringToTestScenario(string testScenario) => testScenario switch
188+
public static TestScenarioName StringToTestScenario(string testScenario) => testScenario switch
186189
{
187-
"BufferedProducerTest" or "BuffProd" => TestScenario.BufferedProducerTest,
188-
"BurstBufferedProducerTest" or "BurstBuffProd" => TestScenario.BurstBufferedProducerTest,
189-
"EventProducerTest" or "EventProd" => TestScenario.EventProducerTest,
190-
"ProcessorTest" or "Processor" => TestScenario.ProcessorTest,
191-
"ConsumerTest" or "Consumer" => TestScenario.ConsumerTest,
190+
"BufferedProducerTest" or "BuffProd" => TestScenarioName.BufferedProducerTest,
191+
"BurstBufferedProducerTest" or "BurstBuffProd" => TestScenarioName.BurstBufferedProducerTest,
192+
"EventProducerTest" or "EventProd" => TestScenarioName.EventProducerTest,
193+
"ProcessorTest" or "Processor" => TestScenarioName.ProcessorTest,
194+
"ConsumerTest" or "Consumer" => TestScenarioName.ConsumerTest,
192195
_ => throw new ArgumentNullException(),
193196
};
194197

sdk/eventhub/Azure.Messaging.EventHubs/stress/src/Scenarios/BufferedProducerTest.cs

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@ namespace Azure.Messaging.EventHubs.Stress;
1212
/// The test scenario responsible for running all of the roles needed for the Buffered Producer test scenario.
1313
/// <summary/>
1414
///
15-
public class BufferedProducerTest
15+
public class BufferedProducerTest : TestScenario
1616
{
17-
/// <summary>The <see cref="TestParameters"/> used to configure this test scenario.</summary>
18-
private readonly TestParameters _testParameters;
19-
20-
/// <summary>The index used to determine which role should be run if this is a distributed test run.</summary>
21-
private readonly string _jobIndex;
22-
23-
/// <summary> The <see cref="Metrics"/> instance used to send metrics to application insights.</summary>
24-
private Metrics _metrics;
17+
/// <summary> The name of this test.</summary>
18+
public override string Name { get; } = "BufferedProducerTest";
2519

2620
/// <summary> The array of <see cref="Role"/>s needed to run this test scenario.</summary>
27-
private static Role[] _roles = {Role.BufferedPublisher, Role.BufferedPublisher};
21+
public override Role[] Roles { get; } = {Role.BufferedPublisher, Role.BufferedPublisher};
2822

2923
/// <summary>
3024
/// Initializes a new <see cref="BufferedProducerTest"/> instance.
@@ -35,60 +29,7 @@ public class BufferedProducerTest
3529
/// <param name="jobIndex">An optional index used to determine which role should be run if this is a distributed run.</param>
3630
///
3731
public BufferedProducerTest(TestParameters testParameters,
38-
Metrics metrics,
39-
string jobIndex = default)
40-
{
41-
_testParameters = testParameters;
42-
_jobIndex = jobIndex;
43-
_metrics = metrics;
44-
_metrics.Client.Context.GlobalProperties["TestRunID"] = $"net-buff-prod-{Guid.NewGuid().ToString()}";
45-
}
46-
47-
/// <summary>
48-
/// Runs all of the roles required for this instance of the Buffered Producer test scenario.
49-
/// </summary>
50-
///
51-
/// <param name="cancellationToken">A <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
52-
///
53-
public async Task RunTestAsync(CancellationToken cancellationToken)
32+
Metrics metrics) : base(testParameters, metrics, $"net-buff-prod-{Guid.NewGuid().ToString()}")
5433
{
55-
var runAllRoles = !int.TryParse(_jobIndex, out var roleIndex);
56-
var testRunTasks = new List<Task>();
57-
58-
if (runAllRoles)
59-
{
60-
foreach (Role role in _roles)
61-
{
62-
testRunTasks.Add(RunRoleAsync(role, cancellationToken));
63-
}
64-
}
65-
else
66-
{
67-
testRunTasks.Add(RunRoleAsync(_roles[roleIndex], cancellationToken));
68-
}
69-
70-
await Task.WhenAll(testRunTasks).ConfigureAwait(false);
71-
}
72-
73-
/// <summary>
74-
/// Creates a role instance and runs that role.
75-
/// </summary>
76-
///
77-
/// <param name="role">The <see cref="Role"/> to run.</param>
78-
/// <param name="cancellationToken">A <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
79-
///
80-
private Task RunRoleAsync(Role role,
81-
CancellationToken cancellationToken)
82-
{
83-
switch (role)
84-
{
85-
case Role.BufferedPublisher:
86-
var publisherConfiguration = new BufferedPublisherConfiguration();
87-
var publisher = new BufferedPublisher(_testParameters, publisherConfiguration, _metrics);
88-
return Task.Run(() => publisher.RunAsync(cancellationToken));
89-
90-
default:
91-
throw new NotSupportedException($"Running role { role.ToString() } is not supported by this test scenario.");
92-
}
9334
}
9435
}

sdk/eventhub/Azure.Messaging.EventHubs/stress/src/Scenarios/BurstBufferedProducerTest.cs

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,14 @@ namespace Azure.Messaging.EventHubs.Stress;
1212
/// The test scenario responsible for running all of the roles needed for the burst Buffered Producer test scenario.
1313
/// <summary/>
1414
///
15-
public class BurstBufferedProducerTest
15+
public class BurstBufferedProducerTest : TestScenario
1616
{
17-
/// <summary>The <see cref="TestParameters"/> used to configure this test scenario.</summary>
18-
private readonly TestParameters _testParameters;
19-
20-
/// <summary>The index used to determine which role should be run if this is a distributed test run.</summary>
21-
private readonly string _jobIndex;
22-
23-
/// <summary> The <see cref="Metrics"/> instance used to send metrics to application insights.</summary>
24-
private Metrics _metrics;
17+
/// <summary> The name of this test.</summary>
18+
public override string Name { get; } = "BurstBufferedProducerTest";
2519

2620
/// <summary> The set of <see cref="Role"/>s needed to run this test scenario.</summary>
2721

28-
private static Role[] _roles = {Role.BufferedPublisher};
22+
public override Role[] Roles { get; } = {Role.BufferedPublisher};
2923

3024
/// <summary>
3125
/// Initializes a new <see cref="BurstBufferedProducerTest"/> instance.
@@ -36,60 +30,7 @@ public class BurstBufferedProducerTest
3630
/// <param name="jobIndex">An optional index used to determine which role should be run if this is a distributed run.</param>
3731
///
3832
public BurstBufferedProducerTest(TestParameters testParameters,
39-
Metrics metrics,
40-
string jobIndex = default)
41-
{
42-
_testParameters = testParameters;
43-
_jobIndex = jobIndex;
44-
_metrics = metrics;
45-
_metrics.Client.Context.GlobalProperties["TestRunID"] = $"net-burst-buff-{Guid.NewGuid().ToString()}";
46-
}
47-
48-
/// <summary>
49-
/// Runs all of the roles required for this instance of the burst Buffered Producer test scenario.
50-
/// </summary>
51-
///
52-
/// <param name="cancellationToken">A <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
53-
///
54-
public async Task RunTestAsync(CancellationToken cancellationToken)
33+
Metrics metrics) : base(testParameters, metrics, $"net-burst-buff-{Guid.NewGuid().ToString()}")
5534
{
56-
var runAllRoles = !int.TryParse(_jobIndex, out var roleIndex);
57-
var testRunTasks = new List<Task>();
58-
59-
if (runAllRoles)
60-
{
61-
foreach (Role role in _roles)
62-
{
63-
testRunTasks.Add(RunRoleAsync(role, cancellationToken));
64-
}
65-
}
66-
else
67-
{
68-
testRunTasks.Add(RunRoleAsync(_roles[roleIndex], cancellationToken));
69-
}
70-
71-
await Task.WhenAll(testRunTasks).ConfigureAwait(false);
72-
}
73-
74-
/// <summary>
75-
/// Creates a role instance and runs that role.
76-
/// </summary>
77-
///
78-
/// <param name="role">The <see cref="Role"/> to run.</param>
79-
/// <param name="cancellationToken">A <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
80-
///
81-
private Task RunRoleAsync(Role role,
82-
CancellationToken cancellationToken)
83-
{
84-
switch (role)
85-
{
86-
case Role.BufferedPublisher:
87-
var publisherConfiguration = new BufferedPublisherConfiguration();
88-
var publisher = new BufferedPublisher(_testParameters, publisherConfiguration, _metrics);
89-
return Task.Run(() => publisher.RunAsync(cancellationToken));
90-
91-
default:
92-
throw new NotSupportedException($"Running role { role.ToString() } is not supported by this test scenario.");
93-
}
9435
}
9536
}

0 commit comments

Comments
 (0)