etcdserver: fix data race in cluster
The data race happens when etcd updates member attributes and fetches member info in http handler at the same time.
This commit is contained in:
@ -18,6 +18,7 @@ package etcdserver
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -88,3 +89,21 @@ func TestMemberPick(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMemberClone(t *testing.T) {
|
||||
tests := []*Member{
|
||||
newTestMemberp(1, nil, "abc", nil),
|
||||
newTestMemberp(1, []string{"http://a"}, "abc", nil),
|
||||
newTestMemberp(1, nil, "abc", []string{"http://b"}),
|
||||
newTestMemberp(1, []string{"http://a"}, "abc", []string{"http://b"}),
|
||||
}
|
||||
for i, tt := range tests {
|
||||
nm := tt.Clone()
|
||||
if nm == tt {
|
||||
t.Errorf("#%d: the pointers are the same, and clone doesn't happen", i)
|
||||
}
|
||||
if !reflect.DeepEqual(nm, tt) {
|
||||
t.Errorf("#%d: member = %+v, want %+v", i, nm, tt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user