Questions about the tinykv project 3A LeaderTransferAfterSnapshot3A test

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tinykv project3A LeaderTransferAfterSnapshot3A 测试疑问

| username: raygift

After implementing snapshot and leaderTransferee, running TestLeaderTransferAfterSnapshot3A reports an error. The direct cause of the error is that the target node 2 specified for leader transfer did not successfully execute hup() to initiate an election due to the presence of a pendingSnapshot. Referring to this test in etcd, it is found that the test case executes advance, which allows the follower’s pendingSnapshot to be cleared. However, TestLeaderTransferAfterSnapshot3A does not call advance, resulting in the follower’s applied snapshot not being cleared. Has anyone encountered this issue? Can the advance logic be omitted?

etcd/raft/raft_test.go

func TestLeaderTransferAfterSnapshot(t *testing.T) {
    nt := newNetwork(nil, nil, nil)
    nt.send(pb.Message{From: 1, To: 1, Type: pb.MsgHup})

    nt.isolate(3)
...
...

    // Apply snapshot and resume progress
    follower := nt.peers[3].(*raft)
    ready := newReady(follower, &SoftState{}, pb.HardState{})
    nt.storage[3].ApplySnapshot(ready.Snapshot)
    **follower.advance(ready)**
    nt.msgHook = nil
    nt.send(filtered)

    checkLeaderTransferState(t, lead, StateFollower, 3)
}