Skip to content

DocumentClient: Adds tests for PartitionKeyRangeLocation disposal#5778

Merged
kirankumarkolli merged 3 commits into
masterfrom
users/kirankk/dispose-partition-endpoint-tests
Apr 13, 2026
Merged

DocumentClient: Adds tests for PartitionKeyRangeLocation disposal#5778
kirankumarkolli merged 3 commits into
masterfrom
users/kirankk/dispose-partition-endpoint-tests

Conversation

@kirankumarkolli
Copy link
Copy Markdown
Member

Description

Adds unit tests covering the fix in PR #5777 where DocumentClient.Dispose() was missing disposal of PartitionKeyRangeLocation (GlobalPartitionEndpointManagerCore), causing the circuit breaker failback loop timer to leak.

Tests added to GlobalPartitionEndpointManagerUnitTests:

  • Dispose_CancelsCancellationTokenSource: verifies cancellation token is cancelled after dispose, preventing background loop re-initialization
  • Dispose_IsIdempotent: multiple dispose calls are safe (no exceptions)
  • Dispose_StopsBackgroundFailbackLoop: background callback stops firing after dispose
  • NoOp_DoesNotImplementIDisposable: confirms GlobalPartitionEndpointManagerNoOp is not IDisposable

New DocumentClientDisposeTests class:

  • Dispose_DisposesPartitionKeyRangeLocationWhenIDisposable: verifies property is disposed, nulled, and manager's background loop is stopped
  • Dispose_HandlesNonDisposablePartitionKeyRangeLocation: GlobalPartitionEndpointManagerNoOp doesn't throw
  • Dispose_HandlesNullPartitionKeyRangeLocation: null property (uninitialized client) doesn't throw
  • Dispose_IsIdempotentWithDisposablePartitionKeyRangeLocation: double-dispose is safe end-to-end

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Adds unit tests covering the fix in PR #5777 where DocumentClient.Dispose()
was missing disposal of PartitionKeyRangeLocation (GlobalPartitionEndpointManagerCore),
causing the circuit breaker failback loop timer to leak.

Tests added to GlobalPartitionEndpointManagerUnitTests:
- Dispose_CancelsCancellationTokenSource: verifies cancellation after dispose
- Dispose_IsIdempotent: multiple dispose calls are safe
- Dispose_StopsBackgroundFailbackLoop: background loop stops after dispose
- NoOp_DoesNotImplementIDisposable: confirms NoOp variant is not IDisposable

New DocumentClientDisposeTests class:
- Dispose_DisposesPartitionKeyRangeLocationWhenIDisposable
- Dispose_HandlesNonDisposablePartitionKeyRangeLocation
- Dispose_HandlesNullPartitionKeyRangeLocation
- Dispose_IsIdempotentWithDisposablePartitionKeyRangeLocation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

Comment thread Microsoft.Azure.Cosmos/src/DocumentClient.cs Outdated
- DocumentClient.cs: Replace 'is IDisposable' pattern with simple null check
- Move Dispose_DisposesPartitionKeyRangeLocationWhenIDisposable test to
  GlobalPartitionEndpointManagerUnitTests
- Remove Dispose_CancelsCancellationTokenSource, Dispose_IsIdempotent,
  and NoOp_DoesNotImplementIDisposable tests
- Delete DocumentClientDisposeTests.cs (remaining tests undone)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

Comment thread Microsoft.Azure.Cosmos/src/DocumentClient.cs
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

@kirankumarkolli kirankumarkolli force-pushed the users/kirankk/dispose-partition-endpoint-tests branch from f363392 to cd8b4cc Compare April 12, 2026 21:51
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

@kirankumarkolli kirankumarkolli changed the title [Internal] DocumentClient: Adds tests for PartitionKeyRangeLocation disposal DocumentClient: Fixes DocumentClient to dispose PartitionKeyRangeLocation Apr 12, 2026
@kirankumarkolli kirankumarkolli changed the title DocumentClient: Fixes DocumentClient to dispose PartitionKeyRangeLocation DocumentClient: Adds tests for PartitionKeyRangeLocation disposal Apr 13, 2026
Copy link
Copy Markdown
Member Author

@kirankumarkolli kirankumarkolli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, ready for review

Copy link
Copy Markdown
Member

@kundadebdatta kundadebdatta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants