Skip to content

Commit 1209821

Browse files
committed
Fix DLQ test isolation; re-include SupportsResubmission in the gate
The three DeadLetterQueue tests shared the test-commands queue and its dead-letter sub-queue with no per-test teardown, so a message dead-lettered by one test leaked into the next test's DLQ assertions (GUID / reason mismatches) — environment-dependent: green in CI, red locally. Drain the shared non-session queues (main + dead-letter) in InitializeAsync via ReceiveAndDelete so every test starts clean. With isolation fixed all three DLQ tests pass, so DeadLetterQueue_SupportsResubmission is no longer excluded from the emulator gate. Verified locally against a fresh emulator: command gate 10/10 passing (DLQ trio included).
1 parent df2312d commit 1209821

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

.github/workflows/Azure-Build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ jobs:
112112
run: >-
113113
dotnet test tests/SourceFlow.Cloud.Azure.Tests/SourceFlow.Cloud.Azure.Tests.csproj
114114
--configuration Release --no-build --verbosity normal
115-
--filter "FullyQualifiedName~ServiceBusCommandDispatchingTests&FullyQualifiedName!~DeadLetterQueue_SupportsResubmission&FullyQualifiedName!~SessionHandling_MultipleSessions_ProcessIndependently&FullyQualifiedName!~SessionHandling_PreservesOrderWithinSession"
115+
--filter "FullyQualifiedName~ServiceBusCommandDispatchingTests&FullyQualifiedName!~SessionHandling_MultipleSessions_ProcessIndependently&FullyQualifiedName!~SessionHandling_PreservesOrderWithinSession"
116116
-- RunConfiguration.TestSessionTimeout=600000
117117
118118
- name: Integration — event publishing

tests/SourceFlow.Cloud.Azure.Tests/Integration/ServiceBusCommandDispatchingTests.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ public async Task InitializeAsync()
6767

6868
// Create test queues
6969
await CreateTestQueuesAsync();
70+
71+
// These tests share entities on the emulator (which has no per-test
72+
// teardown). Drain the shared non-session queues and their dead-letter
73+
// sub-queues so each test starts from a clean state — otherwise a message
74+
// dead-lettered by one test leaks into the next test's DLQ assertions.
75+
await DrainQueueAsync("test-commands");
76+
await DrainQueueAsync("test-commands-dedup");
7077
}
7178

7279
public async Task DisposeAsync()
@@ -686,6 +693,43 @@ public async Task DeadLetterQueue_HandlesPoisonMessages()
686693

687694
#region Helper Methods
688695

696+
/// <summary>
697+
/// Empties a queue and its dead-letter sub-queue using ReceiveAndDelete so each
698+
/// test starts from a clean state (the emulator has no admin purge endpoint).
699+
/// </summary>
700+
private async Task DrainQueueAsync(string queueName)
701+
{
702+
foreach (var subQueue in new[] { SubQueue.None, SubQueue.DeadLetter })
703+
{
704+
var receiver = _serviceBusClient!.CreateReceiver(queueName, new ServiceBusReceiverOptions
705+
{
706+
SubQueue = subQueue,
707+
ReceiveMode = ServiceBusReceiveMode.ReceiveAndDelete
708+
});
709+
710+
try
711+
{
712+
while (true)
713+
{
714+
var messages = await receiver.ReceiveMessagesAsync(
715+
maxMessages: 100,
716+
maxWaitTime: TimeSpan.FromMilliseconds(500));
717+
718+
if (messages == null || messages.Count == 0)
719+
break;
720+
}
721+
}
722+
catch (Exception ex)
723+
{
724+
_output.WriteLine($"Error draining {queueName} ({subQueue}): {ex.Message}");
725+
}
726+
finally
727+
{
728+
await receiver.DisposeAsync();
729+
}
730+
}
731+
}
732+
689733
private async Task CreateTestQueuesAsync()
690734
{
691735
var queues = new[]

0 commit comments

Comments
 (0)