pkg/registry now passed race detector.

This commit is contained in:
Nan Deng 2014-06-30 11:04:57 -07:00
parent 0986e96743
commit 3083a33e5f
2 changed files with 15 additions and 2 deletions

View File

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

View File

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