Skip to content

Commit

Permalink
TestRawNodeStart
Browse files Browse the repository at this point in the history
Now also sees the extra Ready cycle.

Signed-off-by: Tobias Grieger <tobias.b.grieger@gmail.com>
  • Loading branch information
tbg committed Sep 20, 2022
1 parent 79bf3b0 commit 02efe51
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions raft/rawnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,18 +659,16 @@ func TestRawNodeReadIndex(t *testing.T) {
// requires the application to bootstrap the state, i.e. it does not accept peers
// and will not create faux configuration change entries.
func TestRawNodeStart(t *testing.T) {
entries := []pb.Entry{
{Term: 1, Index: 2, Data: nil}, // empty entry
{Term: 1, Index: 3, Data: []byte("foo")}, // empty entry
}
want := Ready{
SoftState: &SoftState{Lead: 1, RaftState: StateLeader},
HardState: pb.HardState{Term: 1, Commit: 3, Vote: 1},
Entries: []pb.Entry{
{Term: 1, Index: 2, Data: nil}, // empty entry
{Term: 1, Index: 3, Data: []byte("foo")}, // empty entry
},
CommittedEntries: []pb.Entry{
{Term: 1, Index: 2, Data: nil}, // empty entry
{Term: 1, Index: 3, Data: []byte("foo")}, // empty entry
},
MustSync: true,
SoftState: &SoftState{Lead: 1, RaftState: StateLeader},
HardState: pb.HardState{Term: 1, Commit: 3, Vote: 1},
Entries: nil, // emitted & checked in intermediate Ready cycle
CommittedEntries: entries,
MustSync: false, // since we're only applying, not appending
}

storage := NewMemoryStorage()
Expand Down Expand Up @@ -750,9 +748,24 @@ func TestRawNodeStart(t *testing.T) {
t.Fatal("expected a Ready")
}
rd := rawNode.Ready()
if !reflect.DeepEqual(entries, rd.Entries) {
t.Fatalf("expected to see entries\n%s, not\n%s", DescribeEntries(entries, nil), DescribeEntries(rd.Entries, nil))
}
storage.Append(rd.Entries)
rawNode.Advance(rd)

if !rawNode.HasReady() {
t.Fatal("expected a Ready")
}
rd = rawNode.Ready()
if len(rd.Entries) != 0 {
t.Fatalf("unexpected entries: %s", DescribeEntries(rd.Entries, nil))
}
if rd.MustSync {
t.Fatalf("should not need to sync")
}
rawNode.Advance(rd)

rd.SoftState, want.SoftState = nil, nil

if !reflect.DeepEqual(rd, want) {
Expand Down

0 comments on commit 02efe51

Please sign in to comment.