@@ -215,7 +215,7 @@ func TestCleanupStaleShardStats(t *testing.T) {
215215 shardStats := map [string ]store.ShardStatistics {
216216 "shard-1" : {SmoothedLoad : 1.0 , LastUpdateTime : now .Unix (), LastMoveTime : now .Unix ()},
217217 "shard-2" : {SmoothedLoad : 2.0 , LastUpdateTime : now .Unix (), LastMoveTime : now .Unix ()},
218- "shard-3" : {SmoothedLoad : 3.0 , LastUpdateTime : now .Unix (), LastMoveTime : now .Unix ()},
218+ "shard-3" : {SmoothedLoad : 3.0 , LastUpdateTime : now .Add ( - 2 * time . Second ). Unix (), LastMoveTime : now . Add ( - 2 * time . Second ) .Unix ()},
219219 }
220220
221221 namespaceState := & store.NamespaceState {
@@ -232,6 +232,30 @@ func TestCleanupStaleShardStats(t *testing.T) {
232232 processor .cleanupStaleShardStats (context .Background ())
233233 })
234234
235+ t .Run ("recent shard stats are preserved" , func (t * testing.T ) {
236+ mocks := setupProcessorTest (t , config .NamespaceTypeFixed )
237+ defer mocks .ctrl .Finish ()
238+ processor := mocks .factory .CreateProcessor (mocks .cfg , mocks .store , mocks .election ).(* namespaceProcessor )
239+
240+ now := mocks .timeSource .Now ()
241+
242+ expiredExecutor := now .Add (- 2 * time .Second ).Unix ()
243+ state := & store.NamespaceState {
244+ Executors : map [string ]store.HeartbeatState {
245+ "exec-stale" : {LastHeartbeat : expiredExecutor },
246+ },
247+ ShardAssignments : map [string ]store.AssignedState {},
248+ ShardStats : map [string ]store.ShardStatistics {
249+ "shard-1" : {SmoothedLoad : 5.0 , LastUpdateTime : now .Unix (), LastMoveTime : now .Unix ()},
250+ },
251+ }
252+
253+ mocks .store .EXPECT ().GetState (gomock .Any (), mocks .cfg .Name ).Return (state , nil )
254+ processor .cleanupStaleShardStats (context .Background ())
255+
256+ // No delete expected since stats are recent.
257+ })
258+
235259}
236260
237261func TestRebalance_StoreErrors (t * testing.T ) {
0 commit comments