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
3 changes: 3 additions & 0 deletions .github/workflows/testing-tool-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- name: Build
run: dotnet build tools/testing-tool/TestingTool.slnx --configuration Release

- name: Test
run: dotnet test tools/testing-tool/TestingTool.slnx --configuration Release --no-build

- name: Build container image
uses: docker/build-push-action@v7.4.0
with:
Expand Down
6 changes: 5 additions & 1 deletion tools/testing-tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ puts each failure shape in its own group, and immediate retries are disabled so
| `poison-message` | Poison | 15% deterministic always-fail messages — retry storm |
| `deserialization-failure` | Deserialization | 100% fail with `SerializationException` (bad deployment) |
| `background-noise` | Noise | ~3% always-on baseline — rotates through four exception types (four small groups) |
| `large-messages` | Body | Starts at 3 msg/s (rate is configurable), each body about 256 KiB of JSON text (the wire envelope is slightly larger), above the 100 KB external body storage threshold. 20% deterministic failures with `InvalidDataException`; the other 80% succeed and are audited |
| `large-messages` | Body | Starts at 3 msg/s (rate is configurable), with about 150 KiB of JSON text per body and about 190 KiB after message serialization. Exceeds the 100 KB external body storage threshold and leaves room for headers on Azure Service Bus Standard. 20% deterministic failures with `InvalidDataException`; the other 80% succeed and are audited |

Scenarios are controlled from the web UI, or via:
- `GET /api/scenarios` — list scenarios with live status (category, rate, error counts)
Expand Down Expand Up @@ -114,6 +114,7 @@ tools/testing-tool/
# OTel setup, ServiceControl REST client
TestingTool.Scenarios/ # IScenario contract + the six scenario implementations
TestingTool.Contracts/ # shared DTOs (scenarios, status, jobs, bypass)
TestingTool.Tests/ # Unit tests for the tool itself
TestingTool.AppHost/ # Aspire AppHost — orchestrates platform, tool, and observability stack
obs/ # observability config: OTel Collector, Prometheus, Grafana provisioning
# + prebuilt dashboard
Expand Down Expand Up @@ -263,12 +264,15 @@ on its own, set it to the broker your ServiceControl instance uses:
| Connection string | Transport |
|---|---|
| starts with `amqp:` or `amqps:` (e.g. `amqp://guest:guest@localhost:5672`) | RabbitMQ — quorum queues, conventional routing topology |
| contains an `Endpoint=sb://...` entry (e.g. `Endpoint=sb://my-namespace.servicebus.windows.net/;SharedAccessKeyName=...;SharedAccessKey=...`) | Azure Service Bus — default topic topology. The direct error and audit writers send through the same endpoint, so they use it too |
| SQL Server connection string with `Initial Catalog` or `Database` (e.g. `Server=localhost;Database=Transport;...`) | SQL Server |
| not set or empty | Learning transport (local standalone runs only — ServiceControl won't see the messages) |
| anything else | startup fails with an error naming `ConnectionStrings__transport` |

The selected transport is logged at startup (`Using RabbitMQ transport` etc.).

The Standard Service Bus tier limits a message to 256 KiB including headers. The `large-messages` scenario serializes to about 190 KiB, so it leaves room for headers on Standard and still exceeds the 100 KB external body storage threshold.

## Configuration

All configuration is via environment variables (no files, no database). Settings are in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
namespace TestingTool.Scenarios;

/// <summary>
/// Large message scenario: every body is about 256 KiB, above the default 100 KB external body storage
/// threshold. A deterministic subset of messages (by hash) fails, so both the Audit and Error ingestion
/// paths store large bodies.
/// Exercises external body storage on the Audit and Error paths.
/// JSON string escaping expands the generated body; leave room for headers under Service Bus Standard's 256 KiB limit.
/// </summary>
public sealed class LargeMessagesScenario(string shardId) : ScenarioBase(shardId)
{
public override string Name => "large-messages";
public override string Description => "Publishes about 256 KiB message bodies and fails 20% of them. Exercises external body storage on the Audit and Error paths.";
public override string Description => "Publishes about 190 KiB serialized message bodies and fails 20% of them. Exercises external body storage on the Audit and Error paths.";
public override string Category => "Body";
public override double DefaultRate => 3;
public override int? BodySizeBytes => 256 * 1024;
public override int? BodySizeBytes => 150 * 1024;

private const double FailureRatio = 0.20;

Expand Down
25 changes: 25 additions & 0 deletions tools/testing-tool/TestingTool.Tests/LargeMessagesScenarioTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Text;
using System.Text.Json;
using NUnit.Framework;
using TestingTool.Scenarios;

namespace TestingTool.Tests;

public class LargeMessagesScenarioTests
{
const int ExternalBodyStorageThresholdBytes = 100 * 1024;
const int AzureServiceBusStandardLimitBytes = 256 * 1024;
const int MinimumHeaderHeadroomBytes = 56 * 1024;

[Test]
public void Serialized_body_exceeds_external_storage_threshold_and_leaves_header_headroom()
{
var scenario = new LargeMessagesScenario("test");
var message = new LoadMessage { Sequence = 1, TextBody = MessageTextGenerator.GenerateBody(1, scenario.BodySizeBytes) };

var serializedBytes = Encoding.UTF8.GetByteCount(JsonSerializer.Serialize(message));

Assert.That(serializedBytes, Is.GreaterThan(ExternalBodyStorageThresholdBytes));
Assert.That(serializedBytes, Is.LessThanOrEqualTo(AzureServiceBusStandardLimitBytes - MinimumHeaderHeadroomBytes));
}
}
19 changes: 19 additions & 0 deletions tools/testing-tool/TestingTool.Tests/TestingTool.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TestingTool\TestingTool.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="NUnit" Version="4.6.1" />
<PackageReference Include="NUnit.Analyzers" Version="4.15.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.1" />
</ItemGroup>

</Project>
34 changes: 34 additions & 0 deletions tools/testing-tool/TestingTool.Tests/TransportSelectionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;

namespace TestingTool.Tests;

public class TransportSelectionTests
{
const string ServiceBusConnectionString =
"Endpoint=sb://example.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=ZmFrZQ==";

[TestCase(ServiceBusConnectionString, "AzureServiceBus")]
[TestCase("endpoint=SB://example.servicebus.windows.net/;SharedAccessKeyName=k;SharedAccessKey=ZmFrZQ==", "AzureServiceBus")]
[TestCase("amqp://guest:guest@localhost:5672", "RabbitMQ")]
[TestCase("Server=localhost;Database=Transport;User Id=sa;Password=x;TrustServerCertificate=true", "SqlServer")]
[TestCase("", "Learning")]
public void Selects_transport_from_connection_string(string connectionString, string expected) =>
Assert.That(Select(connectionString).Name, Is.EqualTo(expected));

[TestCase("Endpoint=https://example.servicebus.windows.net/;SharedAccessKey=ZmFrZQ==")]
[TestCase("not a connection string")]
public void Rejects_unrecognised_connection_string(string connectionString) =>
Assert.Throws<InvalidOperationException>(() => Select(connectionString));

static SelectedTransport Select(string connectionString)
{
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string?> { ["ConnectionStrings:transport"] = connectionString })
.Build();
var services = new ServiceCollection();
services.AddTestingToolEndpoint(new TestingToolOptions(), configuration);
return services.BuildServiceProvider().GetRequiredService<SelectedTransport>();
}
}
1 change: 1 addition & 0 deletions tools/testing-tool/TestingTool.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<Project Path="TestingTool.Scenarios/TestingTool.Scenarios.csproj"/>
<Project Path="TestingTool/TestingTool.csproj"/>
<Project Path="TestingTool.AppHost/TestingTool.AppHost.csproj"/>
<Project Path="TestingTool.Tests/TestingTool.Tests.csproj"/>
</Solution>
23 changes: 22 additions & 1 deletion tools/testing-tool/TestingTool/NServiceBusSetup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Data.Common;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Options;
using NServiceBus;
Expand All @@ -18,6 +19,7 @@ public static class NServiceBusEndpointExtensions
/// Aspire AppHost to match the ServiceControl platform transport):
/// <list type="bullet">
/// <item>starts with <c>amqp:</c> or <c>amqps:</c> — RabbitMQ, quorum queues with conventional routing</item>
/// <item>a connection string with an <c>Endpoint=sb://</c> entry — Azure Service Bus, default topic topology</item>
/// <item>a SQL Server connection string naming a database (<c>Initial Catalog</c>/<c>Database</c>) — SQL Server</item>
/// <item>not set or empty — Learning transport, for local standalone runs</item>
/// </list>
Expand Down Expand Up @@ -45,6 +47,11 @@ public static IServiceCollection AddTestingToolEndpoint(this IServiceCollection
transport.UseConventionalRoutingTopology(QueueType.Quorum);
transport.ConnectionString(transportConnectionString);
}
else if (IsAzureServiceBusConnectionString(transportConnectionString))
{
transportName = "AzureServiceBus";
config.UseTransport(new AzureServiceBusTransport(transportConnectionString, TopicTopology.Default));
}
else if (IsSqlServerConnectionString(transportConnectionString))
{
transportName = "SqlServer";
Expand All @@ -54,7 +61,7 @@ public static IServiceCollection AddTestingToolEndpoint(this IServiceCollection
{
throw new InvalidOperationException(
"Unrecognised 'transport' connection string (ConnectionStrings__transport). Expected an " +
"amqp:// or amqps:// URI for RabbitMQ, or a SQL Server connection string with " +
"amqp:// or amqps:// URI for RabbitMQ, an Endpoint=sb://... connection string for Azure Service Bus, or a SQL Server connection string with " +
"Initial Catalog/Database for SQL Server. Leave it unset to use the Learning transport.");
}

Expand Down Expand Up @@ -91,6 +98,20 @@ public static IServiceCollection AddTestingToolEndpoint(this IServiceCollection
return services;
}

static bool IsAzureServiceBusConnectionString(string connectionString)
{
try
{
var builder = new DbConnectionStringBuilder { ConnectionString = connectionString };
return builder.TryGetValue("Endpoint", out var endpoint)
&& endpoint.ToString()!.StartsWith("sb://", StringComparison.OrdinalIgnoreCase);
}
catch (ArgumentException)
{
return false;
}
}

static bool IsSqlServerConnectionString(string connectionString)
{
try
Expand Down
1 change: 1 addition & 0 deletions tools/testing-tool/TestingTool/TestingTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PackageReference Include="NServiceBus.Metrics" Version="6.0.1" />
<PackageReference Include="NServiceBus.Metrics.ServiceControl" Version="6.0.1" />
<PackageReference Include="NServiceBus.RabbitMQ" Version="11.2.2" />
<PackageReference Include="NServiceBus.Transport.AzureServiceBus" Version="6.5.2" />
<PackageReference Include="NServiceBus.Transport.SqlServer" Version="9.1.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.20.1" />
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.20.1-beta.1" />
Expand Down
Loading