TestRawNodeStart
Now also sees the extra Ready cycle.
@@ -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,
+ Entries: nil, // emitted & checked in intermediate Ready cycle
+ CommittedEntries: entries,
+ MustSync: false, // since we're only applying, not appending
}
storage := NewMemoryStorage()
@@ -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) {
