From 0ad0e24a863bdba09596c6c13e038f3613dceca4 Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Wed, 17 Sep 2014 13:12:56 -0700 Subject: [PATCH] etcdserver: use Action to fix possible data race --- etcdserver/server_test.go | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/etcdserver/server_test.go b/etcdserver/server_test.go index 74563121a..63b0b1671 100644 --- a/etcdserver/server_test.go +++ b/etcdserver/server_test.go @@ -36,12 +36,12 @@ func TestDoLocalAction(t *testing.T) { }, { pb.Request{Method: "BADMETHOD", Id: 1}, - Response{}, ErrUnknownMethod, nil, + Response{}, ErrUnknownMethod, []string{}, }, } for i, tt := range tests { - store := &storeRecorder{} - srv := &EtcdServer{Store: store} + st := &storeRecorder{} + srv := &EtcdServer{Store: st} resp, err := srv.Do(context.TODO(), tt.req) if err != tt.werr { @@ -50,8 +50,9 @@ func TestDoLocalAction(t *testing.T) { if !reflect.DeepEqual(resp, tt.wresp) { t.Errorf("#%d: resp = %+v, want %+v", i, resp, tt.wresp) } - if !reflect.DeepEqual(store.action, tt.waction) { - t.Errorf("#%d: action = %+v, want %+v", i, store.action, tt.waction) + action := st.Action() + if !reflect.DeepEqual(action, tt.waction) { + t.Errorf("#%d: action = %+v, want %+v", i, action, tt.waction) } } } @@ -117,20 +118,21 @@ func TestApply(t *testing.T) { }, { pb.Request{Method: "BADMETHOD", Id: 1}, - Response{err: ErrUnknownMethod}, nil, + Response{err: ErrUnknownMethod}, []string{}, }, } for i, tt := range tests { - store := &storeRecorder{} - srv := &EtcdServer{Store: store} + st := &storeRecorder{} + srv := &EtcdServer{Store: st} resp := srv.apply(tt.req) if !reflect.DeepEqual(resp, tt.wresp) { t.Errorf("#%d: resp = %+v, want %+v", i, resp, tt.wresp) } - if !reflect.DeepEqual(store.action, tt.waction) { - t.Errorf("#%d: action = %+v, want %+v", i, store.action, tt.waction) + action := st.Action() + if !reflect.DeepEqual(action, tt.waction) { + t.Errorf("#%d: action = %+v, want %+v", i, action, tt.waction) } } } @@ -241,8 +243,9 @@ func TestDoProposal(t *testing.T) { resp, err := srv.Do(ctx, tt) srv.Stop() - if len(st.action) != 1 { - t.Errorf("#%d: len(action) = %d, want 1", i, len(st.action)) + action := st.Action() + if len(action) != 1 { + t.Errorf("#%d: len(action) = %d, want 1", i, len(action)) } if err != nil { t.Fatalf("#%d: err = %v, want nil", i, err) @@ -276,8 +279,9 @@ func TestDoProposalCancelled(t *testing.T) { cancel() <-done - if len(st.action) != 0 { - t.Errorf("len(action) = %v, want 0", len(st.action)) + action := st.Action() + if len(action) != 0 { + t.Errorf("len(action) = %v, want 0", len(action)) } if err != context.Canceled { t.Fatalf("err = %v, want %v", err, context.Canceled) @@ -316,8 +320,9 @@ func TestDoProposalStopped(t *testing.T) { srv.Stop() <-done - if len(st.action) != 0 { - t.Errorf("len(action) = %v, want 0", len(st.action)) + action := st.Action() + if len(action) != 0 { + t.Errorf("len(action) = %v, want 0", len(action)) } if err != ErrStopped { t.Errorf("err = %v, want %v", err, ErrStopped)