@@ -52,56 +52,47 @@ describe("PartitionedFetchState getMostBehindPartitions", () => {
5252 mockFetchState (~latestFetchedBlockNumber = 3 ),
5353 }
5454 let partitionedFetchState = mockPartitionedFetchState (~partitions )
55- it (
56- "With multiple partitions always returns the most behind partitions up to the max concurrency level" ,
57- () => {
58- let maxNumQueries = 3
59- let partitionsCurrentlyFetching = Set .Int .empty
55+ it ("With multiple partitions always returns the most behind partitions first" , () => {
56+ let partitionsCurrentlyFetching = Set .Int .empty
6057
61- let mostBehindPartitions =
62- partitionedFetchState -> PartitionedFetchState .getMostBehindPartitions (
63- ~maxNumQueries ,
64- ~maxPerChainQueueSize = 10 ,
65- ~partitionsCurrentlyFetching ,
66- )
67-
68- Assert .equal (mostBehindPartitions -> Array .length , maxNumQueries )
69-
70- let partitionIds = mostBehindPartitions -> Array .map (p => p .partitionId )
71- Assert .deepEqual (
72- partitionIds ,
73- [2 , 3 , 4 ],
74- ~message = "Should have returned the partitions with the lowest latestFetchedBlock" ,
58+ let mostBehindPartitions =
59+ partitionedFetchState -> PartitionedFetchState .getMostBehindPartitions (
60+ ~maxPerChainQueueSize = 10 ,
61+ ~partitionsCurrentlyFetching ,
7562 )
76- },
77- )
63+
64+ let partitionIds = mostBehindPartitions -> Array .map (p => p .partitionId )
65+ Assert .deepEqual (
66+ partitionIds ,
67+ [2 , 3 , 4 , 0 , 1 ],
68+ ~message = "Should have returned the partitions with the lowest latestFetchedBlock first" ,
69+ )
70+ })
7871
7972 it ("Will not return partitions that are currently fetching" , () => {
80- let maxNumQueries = 3
8173 let partitionsCurrentlyFetching = Set .Int .fromArray ([2 , 3 ])
8274
8375 let mostBehindPartitions =
8476 partitionedFetchState -> PartitionedFetchState .getMostBehindPartitions (
85- ~maxNumQueries ,
8677 ~maxPerChainQueueSize = 10 ,
8778 ~partitionsCurrentlyFetching ,
8879 )
8980
9081 Assert .equal (
9182 mostBehindPartitions -> Array .length ,
92- maxNumQueries - partitionsCurrentlyFetching -> Set .Int .size ,
83+ partitionedFetchState .partitions -> Js .Array2 .length -
84+ partitionsCurrentlyFetching -> Set .Int .size ,
9385 )
9486
9587 let partitionIds = mostBehindPartitions -> Array .map (p => p .partitionId )
9688 Assert .deepEqual (
9789 partitionIds ,
98- [4 ],
90+ [4 , 0 , 1 ],
9991 ~message = "Should have returned the partitions with the lowest latestFetchedBlock that are not currently fetching" ,
10092 )
10193 })
10294
103- it ("Should not return partition that is at max partition size" , () => {
104- let maxNumQueries = 3
95+ it ("Should not return partition that is at max queue size" , () => {
10596 let partitions = list {
10697 mockFetchState (~latestFetchedBlockNumber = 4 ),
10798 mockFetchState (~latestFetchedBlockNumber = 5 ),
@@ -119,7 +110,6 @@ describe("PartitionedFetchState getMostBehindPartitions", () => {
119110
120111 let mostBehindPartitions =
121112 partitionedFetchState -> PartitionedFetchState .getMostBehindPartitions (
122- ~maxNumQueries ,
123113 ~maxPerChainQueueSize = 10 , //each partition should therefore have a max of 2 events
124114 ~partitionsCurrentlyFetching = Set .Int .empty ,
125115 )
@@ -133,7 +123,6 @@ describe("PartitionedFetchState getMostBehindPartitions", () => {
133123 })
134124
135125 it ("if need be should return less than maxNum queries if all partitions at their max" , () => {
136- let maxNumQueries = 3
137126 let partitions = list {
138127 mockFetchState (~latestFetchedBlockNumber = 4 ),
139128 mockFetchState (~latestFetchedBlockNumber = 5 ),
@@ -154,7 +143,6 @@ describe("PartitionedFetchState getMostBehindPartitions", () => {
154143
155144 let mostBehindPartitions =
156145 partitionedFetchState -> PartitionedFetchState .getMostBehindPartitions (
157- ~maxNumQueries ,
158146 ~maxPerChainQueueSize = 10 , //each partition should therefore have a max of 2 events
159147 ~partitionsCurrentlyFetching = Set .Int .empty ,
160148 )
0 commit comments