Skip to content
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

Change Feed Processor: Fixes disposal of unused CancellationTokenSource #4220

Merged
merged 5 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public override async Task AddOrUpdateLeaseAsync(DocumentServiceLease lease)
throw;
}

PartitionSupervisor supervisor = this.partitionSupervisorFactory.Create(lease);
this.ProcessPartitionAsync(supervisor, lease).LogException();
this.ProcessPartitionAsync(lease).LogException();
}

public override async Task ShutdownAsync()
Expand Down Expand Up @@ -146,8 +145,10 @@ private async Task RemoveLeaseAsync(DocumentServiceLease lease, bool wasAcquired
}
}

private async Task ProcessPartitionAsync(PartitionSupervisor partitionSupervisor, DocumentServiceLease lease)
private async Task ProcessPartitionAsync(DocumentServiceLease lease)
{
using PartitionSupervisor partitionSupervisor = this.partitionSupervisorFactory.Create(lease);

try
{
await partitionSupervisor.RunAsync(this.shutdownCts.Token).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public async Task Controller_ShouldSignalSynchronizerSplitPartition_IfPartitionS
await sut.ShutdownAsync().ConfigureAwait(false);

Mock.Get(synchronizer).VerifyAll();

Mock.Get(partitionSupervisor)
.Verify(s => s.Dispose(), Times.Once);
}

[TestMethod]
Expand Down Expand Up @@ -76,6 +79,9 @@ public async Task Controller_ShouldPassLastKnownContinuationTokenToSynchronizer_
await sut.ShutdownAsync().ConfigureAwait(false);

Mock.Get(synchronizer).VerifyAll();

Mock.Get(partitionSupervisor)
.Verify(s => s.Dispose(), Times.Once);
}

[TestMethod]
Expand Down Expand Up @@ -108,6 +114,9 @@ public async Task Controller_ShouldCopyParentLeaseProperties_IfPartitionSplitHap
.VerifySet(l => l.Properties = customProperties, Times.Once);
Mock.Get(leaseChild2)
.VerifySet(l => l.Properties = customProperties, Times.Once);

Mock.Get(partitionSupervisor)
.Verify(s => s.Dispose(), Times.Once);
}

[TestMethod]
Expand All @@ -132,6 +141,9 @@ public async Task Controller_ShouldKeepParentLease_IfSplitThrows()
await sut.ShutdownAsync().ConfigureAwait(false);

Mock.Get(leaseManager).Verify(manager => manager.DeleteAsync(lease), Times.Never);

Mock.Get(partitionSupervisor)
.Verify(s => s.Dispose(), Times.Once);
}

[TestMethod]
Expand Down Expand Up @@ -180,6 +192,13 @@ public async Task Controller_ShouldRunProcessingOnChildPartitions_IfHappyPath()

monitor.Verify(m => m.NotifyLeaseAcquireAsync(leaseChild1.CurrentLeaseToken), Times.Once);
monitor.Verify(m => m.NotifyLeaseReleaseAsync(leaseChild2.CurrentLeaseToken), Times.Once);

Mock.Get(partitionSupervisor)
.Verify(s => s.Dispose(), Times.Once);
Mock.Get(partitionSupervisor1)
.Verify(s => s.Dispose(), Times.Once);
Mock.Get(partitionSupervisor2)
.Verify(s => s.Dispose(), Times.Once);
}

[TestMethod]
Expand Down