mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: nodes return sorted ids
This makes raft.softState return the same result when its soft state is not changed.
This commit is contained in:
parent
3f3fc05c8f
commit
78cbb1512c
@ -531,6 +531,7 @@ func (r *raft) nodes() []uint64 {
|
||||
for k := range r.prs {
|
||||
nodes = append(nodes, k)
|
||||
}
|
||||
sort.Sort(uint64Slice(nodes))
|
||||
return nodes
|
||||
}
|
||||
|
||||
|
@ -997,7 +997,6 @@ func TestRestore(t *testing.T) {
|
||||
t.Errorf("log.lastTerm = %d, want %d", sm.raftLog.term(s.Index), s.Term)
|
||||
}
|
||||
sg := sm.nodes()
|
||||
sort.Sort(uint64Slice(sg))
|
||||
if !reflect.DeepEqual(sg, s.Nodes) {
|
||||
t.Errorf("sm.Nodes = %+v, want %+v", sg, s.Nodes)
|
||||
}
|
||||
@ -1166,7 +1165,6 @@ func TestAddNode(t *testing.T) {
|
||||
t.Errorf("pendingConf = %v, want false", r.pendingConf)
|
||||
}
|
||||
nodes := r.nodes()
|
||||
sort.Sort(uint64Slice(nodes))
|
||||
wnodes := []uint64{1, 2}
|
||||
if !reflect.DeepEqual(nodes, wnodes) {
|
||||
t.Errorf("nodes = %v, want %v", nodes, wnodes)
|
||||
@ -1210,6 +1208,28 @@ func TestPromotable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRaftNodes(t *testing.T) {
|
||||
tests := []struct {
|
||||
ids []uint64
|
||||
wids []uint64
|
||||
}{
|
||||
{
|
||||
[]uint64{1, 2, 3},
|
||||
[]uint64{1, 2, 3},
|
||||
},
|
||||
{
|
||||
[]uint64{3, 2, 1},
|
||||
[]uint64{1, 2, 3},
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
r := newRaft(1, tt.ids, 10, 1)
|
||||
if !reflect.DeepEqual(r.nodes(), tt.wids) {
|
||||
t.Errorf("#%d: nodes = %+v, want %+v", i, r.nodes(), tt.wids)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ents(terms ...uint64) *raft {
|
||||
ents := []pb.Entry{{}}
|
||||
for _, term := range terms {
|
||||
|
Loading…
x
Reference in New Issue
Block a user