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:
Yicheng Qin
2014-11-07 16:04:09 -08:00
parent 2fc47034ee
commit 014ef0f52d
4 changed files with 52 additions and 8 deletions

View File

@ -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)
}
}
}