From a5a0a09baef9e2980f06bad7055f5e93acb55682 Mon Sep 17 00:00:00 2001 From: jolov Date: Tue, 31 Oct 2023 15:46:35 -0700 Subject: [PATCH 1/2] Fix mocking of session processor --- .../src/Processor/ServiceBusProcessor.cs | 1 + .../tests/Processor/ProcessorTests.cs | 16 ++++++++++++++++ .../tests/Processor/SessionProcessorTests.cs | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Processor/ServiceBusProcessor.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Processor/ServiceBusProcessor.cs index 4be0bd20a0c02..1647a958af5be 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Processor/ServiceBusProcessor.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Processor/ServiceBusProcessor.cs @@ -277,6 +277,7 @@ protected ServiceBusProcessor() { // assign default options since some of the properties reach into the options Options = new ServiceBusProcessorOptions(); + _sessionIds = Array.Empty(); } /// diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Processor/ProcessorTests.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Processor/ProcessorTests.cs index a664f355127cd..61e14485b8816 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Processor/ProcessorTests.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Processor/ProcessorTests.cs @@ -462,6 +462,22 @@ public async Task CannotStartProcessorWhenConnectionIsClosed() await processor.DisposeAsync(); } + [Test] + public void CanUpdateConcurrencyOnMockProcessor() + { + var mockProcessor = new Mock { CallBase = true }; + mockProcessor.Object.UpdateConcurrency(5); + Assert.AreEqual(5, mockProcessor.Object.MaxConcurrentCalls); + } + + [Test] + public void CanUpdatePrefetchOnMockProcessor() + { + var mockProcessor = new Mock() { CallBase = true }; + mockProcessor.Object.UpdatePrefetchCount(10); + Assert.AreEqual(10, mockProcessor.Object.PrefetchCount); + } + [Test] public async Task CloseRespectsCancellationToken() { diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Processor/SessionProcessorTests.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Processor/SessionProcessorTests.cs index 78ac0ea48d30d..73fe92557932a 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Processor/SessionProcessorTests.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Processor/SessionProcessorTests.cs @@ -377,6 +377,7 @@ public async Task CanRaiseEventsOnMockSessionProcessor() await mockProcessor.OnProcessErrorAsync(errorArgs); await mockProcessor.OnSessionInitializingAsync(processSessionArgs); await mockProcessor.OnSessionClosingAsync(processSessionArgs); + mockProcessor.UpdateConcurrency(1, 1); Assert.IsTrue(processMessageCalled); Assert.IsTrue(processErrorCalled); @@ -446,6 +447,23 @@ public async Task CanRaiseLockLostOnMockProcessor() Assert.IsTrue(sessionCloseCalled); } + [Test] + public void CanUpdateConcurrencyOnMockSessionProcessor() + { + var mockProcessor = new MockSessionProcessor(); + mockProcessor.UpdateConcurrency(5, 2); + Assert.AreEqual(5, mockProcessor.MaxConcurrentSessions); + Assert.AreEqual(2, mockProcessor.MaxConcurrentCallsPerSession); + } + + [Test] + public void CanUpdatePrefetchOnMockSessionProcessor() + { + var mockProcessor = new MockSessionProcessor(); + mockProcessor.UpdatePrefetchCount(10); + Assert.AreEqual(10, mockProcessor.PrefetchCount); + } + [Test] public async Task CloseRespectsCancellationToken() { From 2bf9b0712c95773ea5ff1da0cc59fde5e28c0d86 Mon Sep 17 00:00:00 2001 From: jolov Date: Tue, 31 Oct 2023 15:47:38 -0700 Subject: [PATCH 2/2] remove --- .../tests/Processor/SessionProcessorTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Processor/SessionProcessorTests.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Processor/SessionProcessorTests.cs index 73fe92557932a..3075643d65622 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Processor/SessionProcessorTests.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Processor/SessionProcessorTests.cs @@ -377,7 +377,6 @@ public async Task CanRaiseEventsOnMockSessionProcessor() await mockProcessor.OnProcessErrorAsync(errorArgs); await mockProcessor.OnSessionInitializingAsync(processSessionArgs); await mockProcessor.OnSessionClosingAsync(processSessionArgs); - mockProcessor.UpdateConcurrency(1, 1); Assert.IsTrue(processMessageCalled); Assert.IsTrue(processErrorCalled);