mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Fix close of closed channel in Test_Run_Positive_VolumeMountControllerAttachEnabledRace
This commit is contained in:
parent
dad39bf435
commit
4c913a86ea
@ -20,6 +20,7 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -2183,6 +2184,8 @@ func Test_Run_Positive_VolumeMountControllerAttachEnabledRace(t *testing.T) {
|
|||||||
<-stoppedChan
|
<-stoppedChan
|
||||||
|
|
||||||
finished := make(chan interface{})
|
finished := make(chan interface{})
|
||||||
|
finishedOnce := &sync.Once{}
|
||||||
|
|
||||||
fakePlugin.Lock()
|
fakePlugin.Lock()
|
||||||
fakePlugin.UnmountDeviceHook = func(mountPath string) error {
|
fakePlugin.UnmountDeviceHook = func(mountPath string) error {
|
||||||
// Act:
|
// Act:
|
||||||
@ -2196,14 +2199,15 @@ func Test_Run_Positive_VolumeMountControllerAttachEnabledRace(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fakePlugin.WaitForAttachHook = func(spec *volume.Spec, devicePath string, pod *v1.Pod, spectimeout time.Duration) (string, error) {
|
fakePlugin.WaitForAttachHook = func(spec *volume.Spec, devicePath string, pod *v1.Pod, spectimeout time.Duration) (string, error) {
|
||||||
|
defer finishedOnce.Do(func() {
|
||||||
|
close(finished)
|
||||||
|
})
|
||||||
// Assert
|
// Assert
|
||||||
// 4. When the volume is mounted again, expect that UnmountDevice operation did not clear devicePath
|
// 4. When the volume is mounted again, expect that UnmountDevice operation did not clear devicePath
|
||||||
if devicePath == "" {
|
if devicePath == "" {
|
||||||
klog.ErrorS(nil, "Expected WaitForAttach called with devicePath from Node.Status")
|
klog.ErrorS(nil, "Expected WaitForAttach called with devicePath from Node.Status")
|
||||||
close(finished)
|
|
||||||
return "", fmt.Errorf("Expected devicePath from Node.Status")
|
return "", fmt.Errorf("Expected devicePath from Node.Status")
|
||||||
}
|
}
|
||||||
close(finished)
|
|
||||||
return devicePath, nil
|
return devicePath, nil
|
||||||
}
|
}
|
||||||
fakePlugin.Unlock()
|
fakePlugin.Unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user