mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
TestRawNodeStart
Now also sees the extra Ready cycle. Signed-off-by: Tobias Grieger <tobias.b.grieger@gmail.com>
This commit is contained in:
parent
79bf3b0df4
commit
02efe5135d
@ -659,18 +659,16 @@ func TestRawNodeReadIndex(t *testing.T) {
|
|||||||
// requires the application to bootstrap the state, i.e. it does not accept peers
|
// requires the application to bootstrap the state, i.e. it does not accept peers
|
||||||
// and will not create faux configuration change entries.
|
// and will not create faux configuration change entries.
|
||||||
func TestRawNodeStart(t *testing.T) {
|
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{
|
want := Ready{
|
||||||
SoftState: &SoftState{Lead: 1, RaftState: StateLeader},
|
SoftState: &SoftState{Lead: 1, RaftState: StateLeader},
|
||||||
HardState: pb.HardState{Term: 1, Commit: 3, Vote: 1},
|
HardState: pb.HardState{Term: 1, Commit: 3, Vote: 1},
|
||||||
Entries: []pb.Entry{
|
Entries: nil, // emitted & checked in intermediate Ready cycle
|
||||||
{Term: 1, Index: 2, Data: nil}, // empty entry
|
CommittedEntries: entries,
|
||||||
{Term: 1, Index: 3, Data: []byte("foo")}, // empty entry
|
MustSync: false, // since we're only applying, not appending
|
||||||
},
|
|
||||||
CommittedEntries: []pb.Entry{
|
|
||||||
{Term: 1, Index: 2, Data: nil}, // empty entry
|
|
||||||
{Term: 1, Index: 3, Data: []byte("foo")}, // empty entry
|
|
||||||
},
|
|
||||||
MustSync: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
storage := NewMemoryStorage()
|
storage := NewMemoryStorage()
|
||||||
@ -750,9 +748,24 @@ func TestRawNodeStart(t *testing.T) {
|
|||||||
t.Fatal("expected a Ready")
|
t.Fatal("expected a Ready")
|
||||||
}
|
}
|
||||||
rd := rawNode.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)
|
storage.Append(rd.Entries)
|
||||||
rawNode.Advance(rd)
|
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
|
rd.SoftState, want.SoftState = nil, nil
|
||||||
|
|
||||||
if !reflect.DeepEqual(rd, want) {
|
if !reflect.DeepEqual(rd, want) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user