Skip to content

Commit 2649fde

Browse files
[azservicebus] Add in a simple "clearing of session state" test (Azure#19638)
Add in a simple "clearing of session state" test and updating doc comment for function as well.
1 parent f2483c6 commit 2649fde

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

sdk/messaging/azservicebus/session_receiver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ type SetSessionStateOptions struct {
231231
}
232232

233233
// SetSessionState sets the state associated with the session.
234+
// Pass nil for the state parameter to clear the stored session state.
234235
// If the operation fails it can return an *azservicebus.Error type if the failure is actionable.
235236
func (sr *SessionReceiver) SetSessionState(ctx context.Context, state []byte, options *SetSessionStateOptions) error {
236237
err := sr.inner.amqpLinks.Retry(ctx, EventReceiver, "SetSessionState", func(ctx context.Context, lwv *internal.LinksWithID, args *utils.RetryFnArgs) error {

sdk/messaging/azservicebus/session_receiver_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ func TestSessionReceiver_acceptSession(t *testing.T) {
5959
sessionState, err = receiver.GetSessionState(ctx, nil)
6060
require.NoError(t, err)
6161
require.EqualValues(t, "hello", string(sessionState))
62+
63+
// sanity check that we can clear out session state as well.
64+
require.NoError(t, receiver.SetSessionState(ctx, nil, nil))
65+
sessionState, err = receiver.GetSessionState(ctx, nil)
66+
require.NoError(t, err)
67+
require.Nil(t, sessionState)
6268
}
6369

6470
func TestSessionReceiver_blankSessionIDs(t *testing.T) {

0 commit comments

Comments
 (0)