fix data race in kubelet volume test: add lock
Signed-off-by: Paco Xu <paco.xu@daocloud.io> Co-authored-by: Jian Zeng <zengjian.zj@bytedance.com>
This commit is contained in:
parent
355bc3df22
commit
ab055e9ba4
@ -315,8 +315,8 @@ func TestVolumeUnmountAndDetachControllerDisabled(t *testing.T) {
|
||||
1 /* expectedSetUpCallCount */, testKubelet.volumePlugin))
|
||||
|
||||
// Remove pod
|
||||
// TODO: this may not be threadsafe (technically waitForVolumeUnmount)
|
||||
kubelet.podWorkers.(*fakePodWorkers).removeRuntime = map[types.UID]bool{pod.UID: true}
|
||||
// TODO: technically waitForVolumeUnmount
|
||||
kubelet.podWorkers.(*fakePodWorkers).setPodRuntimeBeRemoved(pod.UID)
|
||||
kubelet.podManager.SetPods([]*v1.Pod{})
|
||||
|
||||
assert.NoError(t, kubelet.volumeManager.WaitForUnmount(pod))
|
||||
@ -504,7 +504,7 @@ func TestVolumeUnmountAndDetachControllerEnabled(t *testing.T) {
|
||||
1 /* expectedSetUpCallCount */, testKubelet.volumePlugin))
|
||||
|
||||
// Remove pod
|
||||
kubelet.podWorkers.(*fakePodWorkers).removeRuntime = map[types.UID]bool{pod.UID: true}
|
||||
kubelet.podWorkers.(*fakePodWorkers).setPodRuntimeBeRemoved(pod.UID)
|
||||
kubelet.podManager.SetPods([]*v1.Pod{})
|
||||
|
||||
assert.NoError(t, waitForVolumeUnmount(kubelet.volumeManager, pod))
|
||||
|
@ -105,6 +105,11 @@ func (f *fakePodWorkers) ShouldPodRuntimeBeRemoved(uid types.UID) bool {
|
||||
defer f.statusLock.Unlock()
|
||||
return f.removeRuntime[uid]
|
||||
}
|
||||
func (f *fakePodWorkers) setPodRuntimeBeRemoved(uid types.UID) {
|
||||
f.statusLock.Lock()
|
||||
defer f.statusLock.Unlock()
|
||||
f.removeRuntime = map[types.UID]bool{uid: true}
|
||||
}
|
||||
func (f *fakePodWorkers) ShouldPodContentBeRemoved(uid types.UID) bool {
|
||||
f.statusLock.Lock()
|
||||
defer f.statusLock.Unlock()
|
||||
|
Loading…
Reference in New Issue
Block a user