mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: don't race when waiting for store in TestSnapshot
This commit is contained in:
parent
13c2d32061
commit
cfe09d34b8
@ -844,7 +844,7 @@ func TestSnapshot(t *testing.T) {
|
|||||||
|
|
||||||
s := raft.NewMemoryStorage()
|
s := raft.NewMemoryStorage()
|
||||||
s.Append([]raftpb.Entry{{Index: 1}})
|
s.Append([]raftpb.Entry{{Index: 1}})
|
||||||
st := mockstore.NewRecorder()
|
st := mockstore.NewRecorderStream()
|
||||||
p := mockstorage.NewStorageRecorderStream("")
|
p := mockstorage.NewStorageRecorderStream("")
|
||||||
srv := &EtcdServer{
|
srv := &EtcdServer{
|
||||||
Cfg: &ServerConfig{},
|
Cfg: &ServerConfig{},
|
||||||
@ -858,24 +858,36 @@ func TestSnapshot(t *testing.T) {
|
|||||||
srv.kv = mvcc.New(be, &lease.FakeLessor{}, &srv.consistIndex)
|
srv.kv = mvcc.New(be, &lease.FakeLessor{}, &srv.consistIndex)
|
||||||
srv.be = be
|
srv.be = be
|
||||||
|
|
||||||
|
ch := make(chan struct{}, 2)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
gaction, _ := p.Wait(1)
|
||||||
|
if len(gaction) != 1 {
|
||||||
|
t.Fatalf("len(action) = %d, want 1", len(gaction))
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(gaction[0], testutil.Action{Name: "SaveSnap"}) {
|
||||||
|
t.Errorf("action = %s, want SaveSnap", gaction[0])
|
||||||
|
}
|
||||||
|
ch <- struct{}{}
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
gaction, _ := st.Wait(2)
|
||||||
|
if len(gaction) != 2 {
|
||||||
|
t.Fatalf("len(action) = %d, want 2", len(gaction))
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(gaction[0], testutil.Action{Name: "Clone"}) {
|
||||||
|
t.Errorf("action = %s, want Clone", gaction[0])
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(gaction[1], testutil.Action{Name: "SaveNoCopy"}) {
|
||||||
|
t.Errorf("action = %s, want SaveNoCopy", gaction[1])
|
||||||
|
}
|
||||||
|
ch <- struct{}{}
|
||||||
|
}()
|
||||||
|
|
||||||
srv.snapshot(1, raftpb.ConfState{Nodes: []uint64{1}})
|
srv.snapshot(1, raftpb.ConfState{Nodes: []uint64{1}})
|
||||||
gaction, _ := st.Wait(2)
|
<-ch
|
||||||
if len(gaction) != 2 {
|
<-ch
|
||||||
t.Fatalf("len(action) = %d, want 1", len(gaction))
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(gaction[0], testutil.Action{Name: "Clone"}) {
|
|
||||||
t.Errorf("action = %s, want Clone", gaction[0])
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(gaction[1], testutil.Action{Name: "SaveNoCopy"}) {
|
|
||||||
t.Errorf("action = %s, want SaveNoCopy", gaction[1])
|
|
||||||
}
|
|
||||||
gaction, _ = p.Wait(1)
|
|
||||||
if len(gaction) != 1 {
|
|
||||||
t.Fatalf("len(action) = %d, want 1", len(gaction))
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(gaction[0], testutil.Action{Name: "SaveSnap"}) {
|
|
||||||
t.Errorf("action = %s, want SaveSnap", gaction[0])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Applied > SnapCount should trigger a SaveSnap event
|
// Applied > SnapCount should trigger a SaveSnap event
|
||||||
|
Loading…
x
Reference in New Issue
Block a user