Fix flaky unit test Test_Run_Positive_VolumeMountControllerAttachEnabledRace data race

ref: https://github.com/kubernetes/kubernetes/issues/94568
This commit is contained in:
jornshen 2020-09-10 17:18:07 +08:00
parent 88e3c95d7c
commit b6b462beba

View File

@ -48,14 +48,14 @@ import (
const (
// reconcilerLoopSleepDuration is the amount of time the reconciler loop
// waits between successive executions
reconcilerLoopSleepDuration time.Duration = 1 * time.Nanosecond
reconcilerLoopSleepDuration = 1 * time.Nanosecond
// waitForAttachTimeout is the maximum amount of time a
// operationexecutor.Mount call will wait for a volume to be attached.
waitForAttachTimeout time.Duration = 1 * time.Second
nodeName k8stypes.NodeName = k8stypes.NodeName("mynodename")
kubeletPodsDir string = "fake-dir"
testOperationBackOffDuration time.Duration = 100 * time.Millisecond
reconcilerSyncWaitDuration time.Duration = 10 * time.Second
waitForAttachTimeout = 1 * time.Second
nodeName = k8stypes.NodeName("mynodename")
kubeletPodsDir = "fake-dir"
testOperationBackOffDuration = 100 * time.Millisecond
reconcilerSyncWaitDuration = 10 * time.Second
)
func hasAddedPods() bool { return true }
@ -1791,6 +1791,7 @@ func Test_Run_Positive_VolumeMountControllerAttachEnabledRace(t *testing.T) {
<-stoppedChan
finished := make(chan interface{})
fakePlugin.Lock()
fakePlugin.UnmountDeviceHook = func(mountPath string) error {
// Act:
// 3. While a volume is being unmounted, add it back to the desired state of world
@ -1812,6 +1813,7 @@ func Test_Run_Positive_VolumeMountControllerAttachEnabledRace(t *testing.T) {
close(finished)
return devicePath, nil
}
fakePlugin.Unlock()
// Start the reconciler again.
go reconciler.Run(wait.NeverStop)