-
Notifications
You must be signed in to change notification settings - Fork 192
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
Added support in ServiceBusSessionMessageActions for null in GetSessionState and SetSessionState #2912
base: main
Are you sure you want to change the base?
Conversation
GetSessionStateAsync SetSessionStateAsync Added Tests
@microsoft-github-policy-service agree |
test/Worker.Extensions.Tests/ServiceBus/ServiceBusSessionMessageActionsTests.cs
Outdated
Show resolved
Hide resolved
test/Worker.Extensions.Tests/ServiceBus/ServiceBusSessionMessageActionsTests.cs
Outdated
Show resolved
Hide resolved
test/Worker.Extensions.Tests/ServiceBus/ServiceBusSessionMessageActionsTests.cs
Show resolved
Hide resolved
test/Worker.Extensions.Tests/ServiceBus/ServiceBusSessionMessageActionsTests.cs
Outdated
Show resolved
Hide resolved
/azp run dotnet-worker.public |
Azure Pipelines successfully started running 1 pipeline(s). |
Formatting
@jviau changed to Moq from manual mock. |
Only need to change the tests you added. Thanks! |
test/Worker.Extensions.Tests/ServiceBus/ServiceBusSessionMessageActionsTests.cs
Outdated
Show resolved
Hide resolved
test/Worker.Extensions.Tests/ServiceBus/ServiceBusSessionMessageActionsTests.cs
Outdated
Show resolved
Hide resolved
test/Worker.Extensions.Tests/ServiceBus/ServiceBusSessionMessageActionsTests.cs
Outdated
Show resolved
Hide resolved
test/Worker.Extensions.Tests/ServiceBus/ServiceBusSessionMessageActionsTests.cs
Outdated
Show resolved
Hide resolved
test/Worker.Extensions.Tests/ServiceBus/ServiceBusSessionMessageActionsTests.cs
Outdated
Show resolved
Hide resolved
@@ -43,7 +43,7 @@ protected ServiceBusSessionMessageActions() | |||
public virtual DateTimeOffset SessionLockedUntil { get; protected set; } | |||
|
|||
///<inheritdoc cref="ServiceBusReceiver.CompleteMessageAsync(ServiceBusReceivedMessage, CancellationToken)"/> | |||
public virtual async Task<BinaryData> GetSessionStateAsync( | |||
public virtual async Task<BinaryData?> GetSessionStateAsync( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this be considered a build breaking change? Is this something we are allowing for the worker extensions? If so, we should explicitly document this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, i belive the only way to check for null session state is to
if(binaryDataFromBytes.ToMemory().Length == 0)
if(binaryDataFromBytes.ToArray().Length == 0)
If breaking changes are not to be introduced, maybe it would be better to return BinaryData.Empty rather then BinaryData.FromBytes(memory) in case of empty. Below are my findings.
ReadOnlyMemory<byte> memory = System.Array.Empty<byte>();
BinaryData binaryDataFromBytes = BinaryData.FromBytes(memory);
BinaryData binaryDataFromDataEmpty = BinaryData.Empty;
if (binaryDataFromBytes == BinaryData.Empty) //False
{
Console.WriteLine("binaryDataFromBytes == BinaryData.Empty");
}
if (binaryDataFromDataEmpty == BinaryData.Empty) //True
{
Console.WriteLine("binaryDataFromDataEmpty == BinaryData.Empty");
}
if (binaryDataFromBytes.ToMemory().Length == 0) //True
{
Console.WriteLine("binaryDataFromBytes == ToMemory().Length == 0");
}
if (binaryDataFromDataEmpty.ToMemory().Length == 0) //True
{
Console.WriteLine("binaryDataFromDataEmpty == ToMemory().Length == 0");
}
if (binaryDataFromBytes.ToArray().Length == 0) //True
{
Console.WriteLine("binaryDataFromBytes == ToArray().Length == 0");
}
if (binaryDataFromDataEmpty.ToArray().Length == 0) //True
{
Console.WriteLine("binaryDataFromDataEmpty == ToArray().Length == 0");
}
The documentation (for receiver, not ServiceBusSessionMessageActions) states:
https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-sessions
The methods for managing session state, SetState and GetState, can be found on the session receiver object. A session that had previously no session state returns a null reference for GetState. The previously set session state can be cleared by passing null to the SetState method on the receiver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since BinaryData
is a class
, I not sure if adding ?
is a breaking change. I think it is only compiler metadata impacted, not runtime impact. I can't find anything online to confirm that though. @fabiocav do you know?
But if this is a behavior change or departure from in-proc behavior, that I can't comment on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In-proc returns null for empty SessionState
Added support for ServiceBusSessionMessageActions:
Issue describing the changes in this PR
resolves #2548
Pull request checklist
release_notes.md