-
Notifications
You must be signed in to change notification settings - Fork 335
Remove per-message Task.Run from Service Bus deserialization #1379
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
Merged
Bernd Verst (berndverst)
merged 4 commits into
main
from
berndverst-issue-1376-inline-message-stream
Oct 2, 2026
+138
−3
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
db3a428
Remove Service Bus inline message Task.Run
ea16daf
Address Service Bus deserialization test review feedback
b73ac23
Merge branch 'main' into berndverst-issue-1376-inline-message-stream
berndverst 170eaed
Bump Service Bus patch version to 4.0.4
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
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
135 changes: 135 additions & 0 deletions
135
test/DurableTask.ServiceBus.Tests/ServiceBusUtilsTests.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,135 @@ | ||
| // ---------------------------------------------------------------------------------- | ||
| // 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.IO; | ||
| using System.Threading.Tasks; | ||
| using DurableTask.Core; | ||
| using DurableTask.Core.Common; | ||
| using DurableTask.Core.Settings; | ||
| using DurableTask.Core.Tracking; | ||
| using DurableTask.ServiceBus.Common.Abstraction; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| [TestClass] | ||
| public class ServiceBusUtilsTests | ||
| { | ||
| const string Payload = "inline message payload"; | ||
|
|
||
| [TestMethod] | ||
| public Task UncompressedInlineMessageDeserializationCompletesSynchronously() | ||
| { | ||
| return AssertInlineMessageRoundTrips(CompressionStyle.Never, expectSynchronousCompletion: true); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public Task CompressedInlineMessageDeserializationRoundTrips() | ||
| { | ||
| return AssertInlineMessageRoundTrips(CompressionStyle.Always, expectSynchronousCompletion: false); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task ExternalMessageDeserializationAwaitsBlobStore() | ||
| { | ||
| const string blobKey = "message-blob"; | ||
| var message = new Message(); | ||
| message.UserProperties[ServiceBusConstants.MessageBlobKey] = blobKey; | ||
| message.UserProperties[FrameworkConstants.CompressionTypePropertyName] = | ||
| FrameworkConstants.CompressionTypeNonePropertyValue; | ||
|
|
||
| using (var stream = new MemoryStream()) | ||
| { | ||
| Utils.WriteObjectToStream(stream, Payload); | ||
| stream.Position = stream.Length; | ||
|
|
||
| var blobStore = new DeferredBlobStore(); | ||
| Task<string> deserializationTask = | ||
| ServiceBusUtils.GetObjectFromBrokeredMessageAsync<string>(message, blobStore); | ||
|
|
||
| Assert.AreEqual(blobKey, blobStore.LoadedBlobKey); | ||
| Assert.IsFalse(deserializationTask.IsCompleted); | ||
|
|
||
| blobStore.CompleteLoad(stream); | ||
|
|
||
| Assert.AreEqual(Payload, await deserializationTask); | ||
| Assert.ThrowsException<ObjectDisposedException>(() => stream.ReadByte()); | ||
| } | ||
| } | ||
|
|
||
| static async Task AssertInlineMessageRoundTrips( | ||
| CompressionStyle compressionStyle, | ||
| bool expectSynchronousCompletion) | ||
| { | ||
| Message message = await ServiceBusUtils.GetBrokeredMessageFromObjectAsync( | ||
| Payload, | ||
| new CompressionSettings { Style = compressionStyle }); | ||
|
|
||
| Task<string> deserializationTask = | ||
| ServiceBusUtils.GetObjectFromBrokeredMessageAsync<string>(message, null); | ||
|
|
||
| if (expectSynchronousCompletion) | ||
| { | ||
| Assert.IsTrue( | ||
| deserializationTask.IsCompleted, | ||
| "Inline message deserialization should not require a thread-pool continuation."); | ||
| } | ||
|
|
||
| Assert.AreEqual(Payload, await deserializationTask); | ||
| } | ||
|
|
||
| sealed class DeferredBlobStore : IOrchestrationServiceBlobStore | ||
| { | ||
| readonly TaskCompletionSource<Stream> loadCompletionSource = new TaskCompletionSource<Stream>(); | ||
|
|
||
| public string LoadedBlobKey { get; private set; } | ||
|
|
||
| public string BuildMessageBlobKey(OrchestrationInstance orchestrationInstance, DateTime messageFireTime) | ||
| { | ||
| throw new NotSupportedException(); | ||
| } | ||
|
|
||
| public string BuildSessionBlobKey(string sessionId) | ||
| { | ||
| throw new NotSupportedException(); | ||
| } | ||
|
|
||
| public Task SaveStreamAsync(string blobKey, Stream stream) | ||
| { | ||
| throw new NotSupportedException(); | ||
| } | ||
|
|
||
| public Task<Stream> LoadStreamAsync(string blobKey) | ||
| { | ||
| this.LoadedBlobKey = blobKey; | ||
| return this.loadCompletionSource.Task; | ||
| } | ||
|
|
||
| public Task DeleteStoreAsync() | ||
| { | ||
| throw new NotSupportedException(); | ||
| } | ||
|
|
||
| public Task PurgeExpiredBlobsAsync(DateTime thresholdDateTimeUtc) | ||
| { | ||
| throw new NotSupportedException(); | ||
| } | ||
|
|
||
| public void CompleteLoad(Stream stream) | ||
| { | ||
| this.loadCompletionSource.SetResult(stream); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.