@@ -187,3 +187,46 @@ func TestIndexHashedNodesCoordinator_IsEpochInConfig(t *testing.T) {
187187 exists = ihnc .IsEpochInConfig (epoch + 1 )
188188 assert .False (t , exists )
189189}
190+
191+ func TestIndexHashedNodesCoordinator_RemoveOlderEpochsShouldNotRemoveWhenEpochIsLessThanMaxDelta (t * testing.T ) {
192+ t .Parallel ()
193+
194+ arguments := createArguments ()
195+ ihnc , err := NewIndexHashedNodesCoordinator (arguments )
196+ require .Nil (t , err )
197+
198+ ihnc .nodesConfig [1 ] = & epochNodesConfig {}
199+ ihnc .nodesConfig [2 ] = & epochNodesConfig {}
200+ ihnc .nodesConfig [3 ] = & epochNodesConfig {}
201+
202+ ihnc .removeOlderEpochs (3 , nodesCoordinatorStoredEpochs )
203+
204+ require .Len (t , ihnc .nodesConfig , 4 )
205+ require .Contains (t , ihnc .nodesConfig , uint32 (0 ))
206+ require .Contains (t , ihnc .nodesConfig , uint32 (1 ))
207+ require .Contains (t , ihnc .nodesConfig , uint32 (2 ))
208+ require .Contains (t , ihnc .nodesConfig , uint32 (3 ))
209+ }
210+
211+ func TestIndexHashedNodesCoordinator_RemoveOlderEpochsShouldRemoveOnlyOlderEpochs (t * testing.T ) {
212+ t .Parallel ()
213+
214+ arguments := createArguments ()
215+ ihnc , err := NewIndexHashedNodesCoordinator (arguments )
216+ require .Nil (t , err )
217+
218+ ihnc .nodesConfig [0 ] = & epochNodesConfig {}
219+ ihnc .nodesConfig [1 ] = & epochNodesConfig {}
220+ ihnc .nodesConfig [2 ] = & epochNodesConfig {}
221+ ihnc .nodesConfig [3 ] = & epochNodesConfig {}
222+ ihnc .nodesConfig [4 ] = & epochNodesConfig {}
223+
224+ ihnc .removeOlderEpochs (4 , nodesCoordinatorStoredEpochs )
225+
226+ require .Len (t , ihnc .nodesConfig , 4 )
227+ require .NotContains (t , ihnc .nodesConfig , uint32 (0 ))
228+ require .Contains (t , ihnc .nodesConfig , uint32 (1 ))
229+ require .Contains (t , ihnc .nodesConfig , uint32 (2 ))
230+ require .Contains (t , ihnc .nodesConfig , uint32 (3 ))
231+ require .Contains (t , ihnc .nodesConfig , uint32 (4 ))
232+ }
0 commit comments