From fac38aad3339688e3c015d04d381a49d2b57efea Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Fri, 19 Sep 2014 15:09:04 -0700 Subject: [PATCH] etcdserver: add TestRecvSlowSnapshot --- etcdserver/server_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/etcdserver/server_test.go b/etcdserver/server_test.go index 0645a764f..fd455519a 100644 --- a/etcdserver/server_test.go +++ b/etcdserver/server_test.go @@ -534,6 +534,34 @@ func TestRecvSnapshot(t *testing.T) { } } +// TestRecvSlowSnapshot tests that slow snapshot will not be applied +// to store. +func TestRecvSlowSnapshot(t *testing.T) { + n := newReadyNode() + st := &storeRecorder{} + s := &EtcdServer{ + Store: st, + Send: func(_ []raftpb.Message) {}, + Storage: &storageRecorder{}, + Node: n, + } + + s.Start() + n.readyc <- raft.Ready{Snapshot: raftpb.Snapshot{Index: 1}} + // make goroutines move forward to receive snapshot + testutil.ForceGosched() + action := st.Action() + + n.readyc <- raft.Ready{Snapshot: raftpb.Snapshot{Index: 1}} + // make goroutines move forward to receive snapshot + testutil.ForceGosched() + s.Stop() + + if g := st.Action(); !reflect.DeepEqual(g, action) { + t.Errorf("store action = %v, want %v", g, action) + } +} + // TODO: test wait trigger correctness in multi-server case func TestGetBool(t *testing.T) {