Skip to content

Commit 5844561

Browse files
NinjaRocksclaude
andcommitted
Wire Azure integration tests to the Service Bus emulator
- AzureTestEnvironment.GetServiceBusConnectionString now falls back to AZURE_SERVICEBUS_CONNECTION_STRING (set by CI) and then to the local Service Bus emulator default, instead of returning an empty string that threw on ServiceBusClient construction. - Config.json: add test-commands.fifo (session), test-commands-dedup (duplicate detection), and test-events / test-events-fanout topics so the deterministic dispatching, event-publishing and session suites have their entities pre-declared (the emulator does not create entities at runtime). - Azure-Build.yml: scope the emulator integration step to the deterministic Service Bus messaging suites; align the emulator connection string. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 0350917 commit 5844561

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

.github/azure-emulator/Config.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
{
55
"Name": "sbemulatorns",
66
"Queues": [
7-
{ "Name": "test-commands", "Properties": { "LockDuration": "PT1M", "RequiresDuplicateDetection": true, "DuplicateDetectionHistoryTimeWindow": "PT10M", "MaxDeliveryCount": 5 } },
8-
{ "Name": "test-events", "Properties": { "LockDuration": "PT1M", "MaxDeliveryCount": 5 } },
7+
{ "Name": "test-commands", "Properties": { "LockDuration": "PT1M", "MaxDeliveryCount": 10 } },
8+
{ "Name": "test-commands.fifo", "Properties": { "LockDuration": "PT1M", "RequiresSession": true, "MaxDeliveryCount": 10 } },
9+
{ "Name": "test-commands-dedup", "Properties": { "LockDuration": "PT1M", "RequiresDuplicateDetection": true, "DuplicateDetectionHistoryTimeWindow": "PT10M", "MaxDeliveryCount": 10 } },
910
{ "Name": "autoscaling-test-queue", "Properties": { "MaxDeliveryCount": 5 } },
1011
{ "Name": "autoscaling-small-queue", "Properties": { "MaxDeliveryCount": 5 } },
1112
{ "Name": "autoscaling-medium-queue", "Properties": { "MaxDeliveryCount": 5 } },
@@ -41,6 +42,8 @@
4142
{ "Name": "perf-resource-queue", "Properties": { "MaxDeliveryCount": 5 } }
4243
],
4344
"Topics": [
45+
{ "Name": "test-events", "Properties": {}, "Subscriptions": [ { "Name": "test-subscription", "Properties": { "MaxDeliveryCount": 5 } } ] },
46+
{ "Name": "test-events-fanout", "Properties": {}, "Subscriptions": [ { "Name": "test-subscription", "Properties": { "MaxDeliveryCount": 5 } }, { "Name": "fanout-sub-1", "Properties": { "MaxDeliveryCount": 5 } }, { "Name": "fanout-sub-2", "Properties": { "MaxDeliveryCount": 5 } } ] },
4447
{ "Name": "session-events-topic", "Properties": {}, "Subscriptions": [ { "Name": "session-events-sub", "Properties": { "RequiresSession": true, "MaxDeliveryCount": 5 } } ] },
4548
{ "Name": "session-lock-topic", "Properties": {}, "Subscriptions": [ { "Name": "session-lock-sub", "Properties": { "RequiresSession": true, "MaxDeliveryCount": 5 } } ] },
4649
{ "Name": "session-state-topic", "Properties": {}, "Subscriptions": [ { "Name": "session-state-sub", "Properties": { "RequiresSession": true, "MaxDeliveryCount": 5 } } ] },

.github/workflows/Azure-Build.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
env:
5656
MSSQL_SA_PASSWORD: "SourceFlow!Emulator1"
5757
# Emulator client connection string (documented default for the emulator image).
58-
AZURE_SERVICEBUS_CONNECTION_STRING: "Endpoint=sb://localhost:5672;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true"
58+
AZURE_SERVICEBUS_CONNECTION_STRING: "Endpoint=sb://localhost;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true"
5959
steps:
6060
- uses: actions/checkout@v4
6161
- name: Setup .NET
@@ -89,11 +89,15 @@ jobs:
8989
dotnet restore SourceFlow.Net.sln
9090
dotnet build SourceFlow.Net.sln --configuration Release --no-restore
9191
92-
- name: Run Azure integration tests
92+
# Deterministic Service Bus messaging suites whose entities are declared in
93+
# .github/azure-emulator/Config.json. Key Vault / Managed Identity / monitor /
94+
# telemetry suites need real Azure, and the property/perf suites create many
95+
# queues at runtime (unsupported by the static-entity emulator) — excluded here.
96+
- name: Run Azure Service Bus integration tests (emulator)
9397
run: >-
9498
dotnet test tests/SourceFlow.Cloud.Azure.Tests/SourceFlow.Cloud.Azure.Tests.csproj
9599
--configuration Release --no-build --verbosity normal
96-
--filter "Category=Integration"
100+
--filter "FullyQualifiedName~ServiceBusCommandDispatchingTests|FullyQualifiedName~ServiceBusEventPublishingTests|FullyQualifiedName~ServiceBusEventSessionHandlingTests"
97101
-- RunConfiguration.TestSessionTimeout=600000
98102
99103
- name: Dump emulator logs on failure

tests/SourceFlow.Cloud.Azure.Tests/TestHelpers/AzureTestEnvironment.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,28 @@ public async Task CleanupAsync()
7777
await Task.CompletedTask;
7878
}
7979

80-
public string GetServiceBusConnectionString() => _config.ServiceBusConnectionString;
80+
/// <summary>
81+
/// Default connection string for the local Azure Service Bus emulator
82+
/// (see .github/azure-emulator/docker-compose.yml).
83+
/// </summary>
84+
public const string EmulatorConnectionString =
85+
"Endpoint=sb://localhost;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true";
86+
87+
public string GetServiceBusConnectionString()
88+
{
89+
// 1. Explicit connection string from configuration.
90+
if (!string.IsNullOrEmpty(_config.ServiceBusConnectionString))
91+
return _config.ServiceBusConnectionString;
92+
93+
// 2. Environment override (real Azure namespace or emulator) — set by CI.
94+
var fromEnv = Environment.GetEnvironmentVariable("AZURE_SERVICEBUS_CONNECTION_STRING");
95+
if (!string.IsNullOrEmpty(fromEnv))
96+
return fromEnv;
97+
98+
// 3. Fall back to the local Service Bus emulator. Azurite cannot emulate
99+
// Service Bus, so tests requesting "Azurite" really target the emulator here.
100+
return EmulatorConnectionString;
101+
}
81102
public string GetServiceBusFullyQualifiedNamespace() => _config.FullyQualifiedNamespace;
82103
public string GetKeyVaultUrl() => _config.KeyVaultUrl;
83104

0 commit comments

Comments
 (0)