mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #306 from monnand/registry-race
Solved data races in pkg/registry
This commit is contained in:
commit
655bca7e55
@ -217,6 +217,7 @@ func TestCreateController(t *testing.T) {
|
|||||||
t.Error("Unexpected read from async channel")
|
t.Error("Unexpected read from async channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mockPodRegistry.Lock()
|
||||||
mockPodRegistry.pods = []api.Pod{
|
mockPodRegistry.pods = []api.Pod{
|
||||||
{
|
{
|
||||||
JSONBase: api.JSONBase{ID: "foo"},
|
JSONBase: api.JSONBase{ID: "foo"},
|
||||||
@ -225,8 +226,7 @@ func TestCreateController(t *testing.T) {
|
|||||||
JSONBase: api.JSONBase{ID: "bar"},
|
JSONBase: api.JSONBase{ID: "bar"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
mockPodRegistry.Unlock()
|
||||||
time.Sleep(time.Millisecond * 30)
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Second * 1):
|
case <-time.After(time.Second * 1):
|
||||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
|||||||
package registry
|
package registry
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
)
|
)
|
||||||
@ -25,6 +27,7 @@ type MockPodRegistry struct {
|
|||||||
err error
|
err error
|
||||||
pod *api.Pod
|
pod *api.Pod
|
||||||
pods []api.Pod
|
pods []api.Pod
|
||||||
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeMockPodRegistry(pods []api.Pod) *MockPodRegistry {
|
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) {
|
func (registry *MockPodRegistry) ListPods(selector labels.Selector) ([]api.Pod, error) {
|
||||||
|
registry.Lock()
|
||||||
|
defer registry.Unlock()
|
||||||
if registry.err != nil {
|
if registry.err != nil {
|
||||||
return registry.pods, registry.err
|
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) {
|
func (registry *MockPodRegistry) GetPod(podId string) (*api.Pod, error) {
|
||||||
|
registry.Lock()
|
||||||
|
defer registry.Unlock()
|
||||||
return registry.pod, registry.err
|
return registry.pod, registry.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *MockPodRegistry) CreatePod(machine string, pod api.Pod) error {
|
func (registry *MockPodRegistry) CreatePod(machine string, pod api.Pod) error {
|
||||||
|
registry.Lock()
|
||||||
|
defer registry.Unlock()
|
||||||
return registry.err
|
return registry.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *MockPodRegistry) UpdatePod(pod api.Pod) error {
|
func (registry *MockPodRegistry) UpdatePod(pod api.Pod) error {
|
||||||
|
registry.Lock()
|
||||||
|
defer registry.Unlock()
|
||||||
return registry.err
|
return registry.err
|
||||||
}
|
}
|
||||||
func (registry *MockPodRegistry) DeletePod(podId string) error {
|
func (registry *MockPodRegistry) DeletePod(podId string) error {
|
||||||
|
registry.Lock()
|
||||||
|
defer registry.Unlock()
|
||||||
return registry.err
|
return registry.err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user