Repository navigation
[DurableTask.ServiceBus.Tests] Fix GetHubQueueMaxDeliveryCountsAsync throwing when a hub queue is missing #1423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Davide Montanari (davidemontanari)
wants to merge
2
commits into
Azure:main
from
davidemontanari:davidemontanari/dtfx-sb-test-fix-maxdeliverycount-get
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
test/DurableTask.ServiceBus.Tests/HubQueueMaxDeliveryCountsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // ---------------------------------------------------------------------------------- | ||
| // Copyright Microsoft Corporation | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ---------------------------------------------------------------------------------- | ||
|
|
||
| namespace DurableTask.ServiceBus.Tests | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using Azure.Messaging.ServiceBus; | ||
| using Azure.Messaging.ServiceBus.Administration; | ||
| using DurableTask.ServiceBus.Common.Abstraction; | ||
| using DurableTask.ServiceBus.Settings; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| /// <summary> | ||
| /// Unit tests for <see cref="ServiceBusOrchestrationService.GetHubQueueMaxDeliveryCounts"/>. | ||
| /// These use in-memory queue descriptions so they do not require a live Service Bus namespace. | ||
| /// </summary> | ||
| [TestClass] | ||
| public class HubQueueMaxDeliveryCountsTests | ||
| { | ||
| const string HubName = "testhub"; | ||
| static ServiceBusOrchestrationService CreateService() | ||
| { | ||
| return new ServiceBusOrchestrationService( | ||
| NoOpTokenCredential.NamespaceHostName, | ||
| new NoOpTokenCredential(), | ||
| HubName, | ||
| null, | ||
| null, | ||
| new ServiceBusOrchestrationServiceSettings()); | ||
| } | ||
|
|
||
| static QueueDescription CreateQueue(string name, int maxDeliveryCount) | ||
| { | ||
| QueueProperties properties = ServiceBusModelFactory.QueueProperties( | ||
| name: name, | ||
| lockDuration: TimeSpan.FromMinutes(1), | ||
| maxSizeInMegabytes: 1024, | ||
| requiresDuplicateDetection: false, | ||
| requiresSession: false, | ||
| defaultMessageTimeToLive: TimeSpan.MaxValue, | ||
| autoDeleteOnIdle: TimeSpan.MaxValue, | ||
| deadLetteringOnMessageExpiration: false, | ||
| duplicateDetectionHistoryTimeWindow: TimeSpan.FromMinutes(10), | ||
| maxDeliveryCount: maxDeliveryCount, | ||
| enableBatchedOperations: true, | ||
| status: EntityStatus.Active, | ||
| forwardTo: string.Empty, | ||
| forwardDeadLetteredMessagesTo: string.Empty, | ||
| userMetadata: string.Empty, | ||
| enablePartitioning: false); | ||
|
|
||
| return new QueueDescription(properties); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ReturnsMaxDeliveryCountForEachHubQueue() | ||
| { | ||
| ServiceBusOrchestrationService service = CreateService(); | ||
|
|
||
| Dictionary<string, int> counts = service.GetHubQueueMaxDeliveryCounts(new[] | ||
| { | ||
| CreateQueue($"{HubName}/orchestrator", 10), | ||
| CreateQueue($"{HubName}/worker", 20), | ||
| CreateQueue($"{HubName}/tracking", 30), | ||
| }); | ||
|
|
||
| Assert.AreEqual(10, counts["TaskOrchestration"]); | ||
| Assert.AreEqual(20, counts["TaskActivity"]); | ||
| Assert.AreEqual(30, counts["Tracking"]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ReturnsMinusOneForMissingTrackingQueue() | ||
| { | ||
| // Without an instance store the tracking queue is never created. | ||
| ServiceBusOrchestrationService service = CreateService(); | ||
|
|
||
| Dictionary<string, int> counts = service.GetHubQueueMaxDeliveryCounts(new[] | ||
| { | ||
| CreateQueue($"{HubName}/orchestrator", 10), | ||
| CreateQueue($"{HubName}/worker", 20), | ||
| }); | ||
|
|
||
| Assert.AreEqual(10, counts["TaskOrchestration"]); | ||
| Assert.AreEqual(20, counts["TaskActivity"]); | ||
| Assert.AreEqual(-1, counts["Tracking"]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ReturnsMinusOneForAllQueuesWhenHubDoesNotExist() | ||
| { | ||
| ServiceBusOrchestrationService service = CreateService(); | ||
|
|
||
| Dictionary<string, int> counts = service.GetHubQueueMaxDeliveryCounts(new[] | ||
| { | ||
| CreateQueue("otherhub/orchestrator", 10), | ||
| CreateQueue("otherhub/worker", 20), | ||
| CreateQueue("otherhub/tracking", 30), | ||
| }); | ||
|
|
||
| Assert.AreEqual(-1, counts["TaskOrchestration"]); | ||
| Assert.AreEqual(-1, counts["TaskActivity"]); | ||
| Assert.AreEqual(-1, counts["Tracking"]); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // ---------------------------------------------------------------------------------- | ||
| // Copyright Microsoft Corporation | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ---------------------------------------------------------------------------------- | ||
|
|
||
| namespace DurableTask.ServiceBus.Tests | ||
| { | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Azure.Core; | ||
|
|
||
| /// <summary> | ||
| /// Credential stub for offline tests that construct a <see cref="ServiceBusOrchestrationService"/> | ||
| /// but never contact Service Bus, so no token is ever requested. | ||
| /// </summary> | ||
| sealed class NoOpTokenCredential : TokenCredential | ||
| { | ||
| public const string NamespaceHostName = "test.servicebus.windows.net"; | ||
|
|
||
| public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken) | ||
| => throw new NotSupportedException(); | ||
|
|
||
| public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken) | ||
| => throw new NotSupportedException(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.