Skip to content

Commit

Permalink
Change Feed Processor: Fixes disposal of unused CancellationTokenSour…
Browse files Browse the repository at this point in the history
…ce (#4220)

* Calling dispose

* Tests

* refactoring
  • Loading branch information
ealsur committed Dec 22, 2023
1 parent 1e49b16 commit 5a096d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
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

0 comments on commit 5a096d1

Please sign in to comment.