mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: use status to test node stop
n.Tick() is async. It can be racy when running with n.Stop(). n.Status() is sync and has a feedback mechnism internally. So there wont be any race between n.Status() and n.Stop() call.
This commit is contained in:
parent
0dce29ae57
commit
fc8cd44c72
@ -422,9 +422,7 @@ func TestNodeStop(t *testing.T) {
|
|||||||
close(donec)
|
close(donec)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
elapsed := r.electionElapsed
|
status := n.Status()
|
||||||
n.Tick()
|
|
||||||
testutil.WaitSchedule()
|
|
||||||
n.Stop()
|
n.Stop()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -433,13 +431,15 @@ func TestNodeStop(t *testing.T) {
|
|||||||
t.Fatalf("timed out waiting for node to stop!")
|
t.Fatalf("timed out waiting for node to stop!")
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.electionElapsed != elapsed+1 {
|
emptyStatus := Status{}
|
||||||
t.Errorf("elapsed = %d, want %d", r.electionElapsed, elapsed+1)
|
|
||||||
|
if reflect.DeepEqual(status, emptyStatus) {
|
||||||
|
t.Errorf("status = %v, want not empty", status)
|
||||||
}
|
}
|
||||||
// Further ticks should have no effect, the node is stopped.
|
// Further status should return be empty, the node is stopped.
|
||||||
n.Tick()
|
status = n.Status()
|
||||||
if r.electionElapsed != elapsed+1 {
|
if !reflect.DeepEqual(status, emptyStatus) {
|
||||||
t.Errorf("elapsed = %d, want %d", r.electionElapsed, elapsed+1)
|
t.Errorf("status = %v, want empty", status)
|
||||||
}
|
}
|
||||||
// Subsequent Stops should have no effect.
|
// Subsequent Stops should have no effect.
|
||||||
n.Stop()
|
n.Stop()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user