mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
TestRawNodeBoundedLogGrowthWithPartition
Signed-off-by: Tobias Grieger <tobias.b.grieger@gmail.com>
This commit is contained in:
parent
02efe5135d
commit
f7b0a6ad33
@ -968,6 +968,7 @@ func TestRawNodeBoundedLogGrowthWithPartition(t *testing.T) {
|
|||||||
data := []byte("testdata")
|
data := []byte("testdata")
|
||||||
testEntry := pb.Entry{Data: data}
|
testEntry := pb.Entry{Data: data}
|
||||||
maxEntrySize := uint64(maxEntries * PayloadSize(testEntry))
|
maxEntrySize := uint64(maxEntries * PayloadSize(testEntry))
|
||||||
|
t.Log("maxEntrySize", maxEntrySize)
|
||||||
|
|
||||||
s := newTestMemoryStorage(withPeers(1))
|
s := newTestMemoryStorage(withPeers(1))
|
||||||
cfg := newTestConfig(1, 10, 1, s)
|
cfg := newTestConfig(1, 10, 1, s)
|
||||||
@ -976,20 +977,16 @@ func TestRawNodeBoundedLogGrowthWithPartition(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Become the leader and apply empty entry.
|
||||||
|
rawNode.Campaign()
|
||||||
|
for {
|
||||||
rd := rawNode.Ready()
|
rd := rawNode.Ready()
|
||||||
s.Append(rd.Entries)
|
s.Append(rd.Entries)
|
||||||
rawNode.Advance(rd)
|
rawNode.Advance(rd)
|
||||||
|
if len(rd.CommittedEntries) > 0 {
|
||||||
// Become the leader.
|
|
||||||
rawNode.Campaign()
|
|
||||||
for {
|
|
||||||
rd = rawNode.Ready()
|
|
||||||
s.Append(rd.Entries)
|
|
||||||
if rd.SoftState.Lead == rawNode.raft.id {
|
|
||||||
rawNode.Advance(rd)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
rawNode.Advance(rd)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulate a network partition while we make our proposals by never
|
// Simulate a network partition while we make our proposals by never
|
||||||
@ -1011,12 +1008,25 @@ func TestRawNodeBoundedLogGrowthWithPartition(t *testing.T) {
|
|||||||
|
|
||||||
// Recover from the partition. The uncommitted tail of the Raft log should
|
// Recover from the partition. The uncommitted tail of the Raft log should
|
||||||
// disappear as entries are committed.
|
// disappear as entries are committed.
|
||||||
rd = rawNode.Ready()
|
rd := rawNode.Ready()
|
||||||
if len(rd.CommittedEntries) != maxEntries {
|
if len(rd.Entries) != maxEntries {
|
||||||
t.Fatalf("expected %d entries, got %d", maxEntries, len(rd.CommittedEntries))
|
t.Fatalf("expected %d entries, got %d", maxEntries, len(rd.Entries))
|
||||||
}
|
}
|
||||||
s.Append(rd.Entries)
|
s.Append(rd.Entries)
|
||||||
rawNode.Advance(rd)
|
rawNode.Advance(rd)
|
||||||
|
|
||||||
|
// Entries are appended, but not applied.
|
||||||
|
checkUncommitted(maxEntrySize)
|
||||||
|
|
||||||
|
rd = rawNode.Ready()
|
||||||
|
if len(rd.Entries) != 0 {
|
||||||
|
t.Fatalf("unexpected entries: %s", DescribeEntries(rd.Entries, nil))
|
||||||
|
}
|
||||||
|
if len(rd.CommittedEntries) != maxEntries {
|
||||||
|
t.Fatalf("expected %d entries, got %d", maxEntries, len(rd.CommittedEntries))
|
||||||
|
}
|
||||||
|
rawNode.Advance(rd)
|
||||||
|
|
||||||
checkUncommitted(0)
|
checkUncommitted(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user