From 3083a33e5f974d1bbc4372ee23ce5ec2892900ef Mon Sep 17 00:00:00 2001 From: Nan Deng Date: Mon, 30 Jun 2014 11:04:57 -0700 Subject: [PATCH] pkg/registry now passed race detector. --- pkg/registry/controller_registry_test.go | 4 ++-- pkg/registry/mock_registry.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/registry/controller_registry_test.go b/pkg/registry/controller_registry_test.go index 693db2019c2..73728ca91dc 100644 --- a/pkg/registry/controller_registry_test.go +++ b/pkg/registry/controller_registry_test.go @@ -217,6 +217,7 @@ func TestCreateController(t *testing.T) { t.Error("Unexpected read from async channel") } + mockPodRegistry.Lock() mockPodRegistry.pods = []api.Pod{ { JSONBase: api.JSONBase{ID: "foo"}, @@ -225,8 +226,7 @@ func TestCreateController(t *testing.T) { JSONBase: api.JSONBase{ID: "bar"}, }, } - - time.Sleep(time.Millisecond * 30) + mockPodRegistry.Unlock() select { case <-time.After(time.Second * 1): diff --git a/pkg/registry/mock_registry.go b/pkg/registry/mock_registry.go index 7a3db516cb9..4b620354cdf 100644 --- a/pkg/registry/mock_registry.go +++ b/pkg/registry/mock_registry.go @@ -17,6 +17,8 @@ limitations under the License. package registry import ( + "sync" + "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" ) @@ -25,6 +27,7 @@ type MockPodRegistry struct { err error pod *api.Pod pods []api.Pod + sync.RWMutex } func MakeMockPodRegistry(pods []api.Pod) *MockPodRegistry { @@ -34,6 +37,8 @@ func MakeMockPodRegistry(pods []api.Pod) *MockPodRegistry { } func (registry *MockPodRegistry) ListPods(selector labels.Selector) ([]api.Pod, error) { + registry.RLock() + defer registry.RUnlock() if registry.err != nil { return registry.pods, registry.err } @@ -47,16 +52,24 @@ func (registry *MockPodRegistry) ListPods(selector labels.Selector) ([]api.Pod, } func (registry *MockPodRegistry) GetPod(podId string) (*api.Pod, error) { + registry.RLock() + defer registry.RUnlock() return registry.pod, registry.err } func (registry *MockPodRegistry) CreatePod(machine string, pod api.Pod) error { + registry.RLock() + defer registry.RUnlock() return registry.err } func (registry *MockPodRegistry) UpdatePod(pod api.Pod) error { + registry.RLock() + defer registry.RUnlock() return registry.err } func (registry *MockPodRegistry) DeletePod(podId string) error { + registry.RLock() + defer registry.RUnlock() return registry.err }