mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1699 from jonboulle/node_stop
raft: block Stop() on n.done, support idempotency
This commit is contained in:
@@ -176,7 +176,7 @@ func TestBlockProposal(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestNodeTick ensures that node.Tick() will increase the
|
||||
// elapsed of the underly raft state machine.
|
||||
// elapsed of the underlying raft state machine.
|
||||
func TestNodeTick(t *testing.T) {
|
||||
n := newNode()
|
||||
r := newRaft(1, []uint64{1}, 10, 1)
|
||||
@@ -189,6 +189,40 @@ func TestNodeTick(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestNodeStop ensures that node.Stop() blocks until the node has stopped
|
||||
// processing, and that it is idempotent
|
||||
func TestNodeStop(t *testing.T) {
|
||||
n := newNode()
|
||||
r := newRaft(1, []uint64{1}, 10, 1)
|
||||
donec := make(chan struct{})
|
||||
|
||||
go func() {
|
||||
n.run(r)
|
||||
close(donec)
|
||||
}()
|
||||
|
||||
elapsed := r.elapsed
|
||||
n.Tick()
|
||||
n.Stop()
|
||||
|
||||
select {
|
||||
case <-donec:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatalf("timed out waiting for node to stop!")
|
||||
}
|
||||
|
||||
if r.elapsed != elapsed+1 {
|
||||
t.Errorf("elapsed = %d, want %d", r.elapsed, elapsed+1)
|
||||
}
|
||||
// Further ticks should have no effect, the node is stopped.
|
||||
n.Tick()
|
||||
if r.elapsed != elapsed+1 {
|
||||
t.Errorf("elapsed = %d, want %d", r.elapsed, elapsed+1)
|
||||
}
|
||||
// Subsequent Stops should have no effect.
|
||||
n.Stop()
|
||||
}
|
||||
|
||||
func TestReadyContainUpdates(t *testing.T) {
|
||||
tests := []struct {
|
||||
rd Ready
|
||||
|
||||
Reference in New Issue
Block a user