project2中TestCandidateFallback2AA

在TestCandidateFallback2AA中,为什么1号节点的term为1,而且当1号节点是candidate的时候,为什么收到一个来自2号节点的term为1的append请求,就会转换成follower


func TestCandidateFallback2AA(t *testing.T) {

tests := []pb.Message{

    {From: 2, To: 1, Term: 1, MsgType: pb.MessageType_MsgAppend},

    {From: 2, To: 1, Term: 2, MsgType: pb.MessageType_MsgAppend},

}

for i, tt := range tests {

    r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, NewMemoryStorage())

    r.Step(pb.Message{From: 1, To: 1, MsgType: pb.MessageType_MsgHup})

    if r.State != StateCandidate {

        t.Fatalf("unexpected state = %s, want %s", r.State, StateCandidate)

    }

    r.Step(tt)

    if g := r.State; g != StateFollower {

        t.Errorf("#%d: state = %s, want %s", i, g, StateFollower)

    }

    if g := r.Term; g != tt.Term {

        t.Errorf("#%d: term = %d, want %d", i, g, tt.Term)

    }

}

}

是我傻逼了,想简单了,这个贴已经解决了