Fix flaky HashRangesAreAlwaysComplete test

Adds mechanism to allow in-progress parents to finish (marked as SHARD_END) if testFor1000DifferentValidReshardHierarchyTreeWithSomeInProgressParentsTheHashRangesAreAlwaysComplete detects hole due to merged parent shards still holding an active lease.
This commit is contained in:
furq-aws 2023-03-15 14:21:50 -07:00
parent 04a121a811
commit d3a4fd5569

View file

@ -459,7 +459,12 @@ public class PeriodicShardSyncManagerTest {
List<Lease> leases = generateInitialLeases(maxInitialLeaseCount); List<Lease> leases = generateInitialLeases(maxInitialLeaseCount);
reshard(leases, 5, ReshardType.ANY, maxInitialLeaseCount, true); reshard(leases, 5, ReshardType.ANY, maxInitialLeaseCount, true);
Collections.shuffle(leases); Collections.shuffle(leases);
Assert.assertFalse(periodicShardSyncManager.hasHoleInLeases(streamIdentifier, leases).isPresent()); boolean isHoleInHashRanges = periodicShardSyncManager.hasHoleInLeases(streamIdentifier, leases).isPresent();
if (isHoleInHashRanges) {
finishInProgressParents(leases);
isHoleInHashRanges = periodicShardSyncManager.hasHoleInLeases(streamIdentifier, leases).isPresent();
}
Assert.assertFalse(isHoleInHashRanges);
} }
} }
@ -569,6 +574,13 @@ public class PeriodicShardSyncManagerTest {
return leaseCounter; return leaseCounter;
} }
private void finishInProgressParents(List<Lease> leases) {
leases.stream()
.filter(l -> l.checkpoint() != null && !l.checkpoint().equals(ExtendedSequenceNumber.SHARD_END) &&
l.childShardIds() != null && !l.childShardIds().isEmpty())
.forEach(l -> l.checkpoint(ExtendedSequenceNumber.SHARD_END));
}
private boolean isHeads() { private boolean isHeads() {
return Math.random() <= 0.5; return Math.random() <= 0.5;
} }