diff --git a/.github/workflows/testing-tool-ci.yml b/.github/workflows/testing-tool-ci.yml index 56f8e0df0d..b264a5205c 100644 --- a/.github/workflows/testing-tool-ci.yml +++ b/.github/workflows/testing-tool-ci.yml @@ -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: diff --git a/tools/testing-tool/README.md b/tools/testing-tool/README.md index 4e552362b3..4f2ba3d39d 100644 --- a/tools/testing-tool/README.md +++ b/tools/testing-tool/README.md @@ -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) @@ -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 @@ -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 diff --git a/tools/testing-tool/TestingTool.Scenarios/LargeMessagesScenario.cs b/tools/testing-tool/TestingTool.Scenarios/LargeMessagesScenario.cs index 3e42797b5c..8293beaf8d 100644 --- a/tools/testing-tool/TestingTool.Scenarios/LargeMessagesScenario.cs +++ b/tools/testing-tool/TestingTool.Scenarios/LargeMessagesScenario.cs @@ -3,17 +3,16 @@ namespace TestingTool.Scenarios; /// -/// 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. /// 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; diff --git a/tools/testing-tool/TestingTool.Tests/LargeMessagesScenarioTests.cs b/tools/testing-tool/TestingTool.Tests/LargeMessagesScenarioTests.cs new file mode 100644 index 0000000000..a1946b9a50 --- /dev/null +++ b/tools/testing-tool/TestingTool.Tests/LargeMessagesScenarioTests.cs @@ -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)); + } +} diff --git a/tools/testing-tool/TestingTool.Tests/TestingTool.Tests.csproj b/tools/testing-tool/TestingTool.Tests/TestingTool.Tests.csproj new file mode 100644 index 0000000000..12249a6e1d --- /dev/null +++ b/tools/testing-tool/TestingTool.Tests/TestingTool.Tests.csproj @@ -0,0 +1,19 @@ + + + + net10.0 + false + + + + + + + + + + + + + + diff --git a/tools/testing-tool/TestingTool.Tests/TransportSelectionTests.cs b/tools/testing-tool/TestingTool.Tests/TransportSelectionTests.cs new file mode 100644 index 0000000000..23167a885a --- /dev/null +++ b/tools/testing-tool/TestingTool.Tests/TransportSelectionTests.cs @@ -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(() => Select(connectionString)); + + static SelectedTransport Select(string connectionString) + { + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary { ["ConnectionStrings:transport"] = connectionString }) + .Build(); + var services = new ServiceCollection(); + services.AddTestingToolEndpoint(new TestingToolOptions(), configuration); + return services.BuildServiceProvider().GetRequiredService(); + } +} diff --git a/tools/testing-tool/TestingTool.slnx b/tools/testing-tool/TestingTool.slnx index a8dbbdfe57..a1e67750a1 100644 --- a/tools/testing-tool/TestingTool.slnx +++ b/tools/testing-tool/TestingTool.slnx @@ -3,4 +3,5 @@ + \ No newline at end of file diff --git a/tools/testing-tool/TestingTool/NServiceBusSetup.cs b/tools/testing-tool/TestingTool/NServiceBusSetup.cs index f118655085..499c08d9e8 100644 --- a/tools/testing-tool/TestingTool/NServiceBusSetup.cs +++ b/tools/testing-tool/TestingTool/NServiceBusSetup.cs @@ -1,3 +1,4 @@ +using System.Data.Common; using Microsoft.Data.SqlClient; using Microsoft.Extensions.Options; using NServiceBus; @@ -18,6 +19,7 @@ public static class NServiceBusEndpointExtensions /// Aspire AppHost to match the ServiceControl platform transport): /// /// starts with amqp: or amqps: — RabbitMQ, quorum queues with conventional routing + /// a connection string with an Endpoint=sb:// entry — Azure Service Bus, default topic topology /// a SQL Server connection string naming a database (Initial Catalog/Database) — SQL Server /// not set or empty — Learning transport, for local standalone runs /// @@ -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"; @@ -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."); } @@ -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 diff --git a/tools/testing-tool/TestingTool/TestingTool.csproj b/tools/testing-tool/TestingTool/TestingTool.csproj index d3e979aae8..f24d5ee8e6 100644 --- a/tools/testing-tool/TestingTool/TestingTool.csproj +++ b/tools/testing-tool/TestingTool/TestingTool.csproj @@ -17,6 +17,7 @@ +