@@ -225,6 +225,38 @@ func TestUpStore(t *testing.T) {
225
225
assert .True (t , strings .Contains (err .Error (), "not found" ))
226
226
}
227
227
228
+ func TestShardHeartbeatWithLease (t * testing.T ) {
229
+ _ , opt , err := newTestScheduleConfig ()
230
+ assert .NoError (t , err )
231
+
232
+ cluster := newTestRaftCluster (opt , storage .NewTestStorage (), core .NewBasicCluster (nil ))
233
+ stores := newTestStores (3 , "2.0.0" )
234
+ for _ , store := range stores {
235
+ assert .NoError (t , cluster .putStoreLocked (store ))
236
+ }
237
+
238
+ shards := newTestShards (1 , 3 )
239
+ shard := shards [0 ]
240
+
241
+ assert .NoError (t , cluster .processShardHeartbeat (shard ))
242
+ assert .Nil (t , cluster .GetShard (shard .Meta .ID ).GetLease ())
243
+
244
+ // first lease
245
+ newShard := shard .Clone (core .WithLease (& metapb.EpochLease {Epoch : 1 , ReplicaID : shard .Meta .Replicas [0 ].ID }))
246
+ assert .NoError (t , cluster .processShardHeartbeat (newShard ))
247
+ assert .Equal (t , & metapb.EpochLease {Epoch : 1 , ReplicaID : shard .Meta .Replicas [0 ].ID }, cluster .GetShard (shard .Meta .ID ).GetLease ())
248
+
249
+ // new lease
250
+ newShard = shard .Clone (core .WithLease (& metapb.EpochLease {Epoch : 2 , ReplicaID : shard .Meta .Replicas [1 ].ID }))
251
+ assert .NoError (t , cluster .processShardHeartbeat (newShard ))
252
+ assert .Equal (t , & metapb.EpochLease {Epoch : 2 , ReplicaID : shard .Meta .Replicas [1 ].ID }, cluster .GetShard (shard .Meta .ID ).GetLease ())
253
+
254
+ // invalid lease
255
+ newShard = shard .Clone (core .WithLease (& metapb.EpochLease {Epoch : 1 , ReplicaID : shard .Meta .Replicas [2 ].ID }))
256
+ assert .NoError (t , cluster .processShardHeartbeat (newShard ))
257
+ assert .Equal (t , & metapb.EpochLease {Epoch : 2 , ReplicaID : shard .Meta .Replicas [1 ].ID }, cluster .GetShard (shard .Meta .ID ).GetLease ())
258
+ }
259
+
228
260
func TestShardHeartbeat (t * testing.T ) {
229
261
_ , opt , err := newTestScheduleConfig ()
230
262
assert .NoError (t , err )
0 commit comments