Skip to content

Commit 4c913a8

Browse files
committed
Fix close of closed channel in Test_Run_Positive_VolumeMountControllerAttachEnabledRace
1 parent dad39bf commit 4c913a8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/kubelet/volumemanager/reconciler/reconciler_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"crypto/md5"
2121
"fmt"
2222
"path/filepath"
23+
"sync"
2324
"testing"
2425
"time"
2526

@@ -2183,6 +2184,8 @@ func Test_Run_Positive_VolumeMountControllerAttachEnabledRace(t *testing.T) {
21832184
<-stoppedChan
21842185

21852186
finished := make(chan interface{})
2187+
finishedOnce := &sync.Once{}
2188+
21862189
fakePlugin.Lock()
21872190
fakePlugin.UnmountDeviceHook = func(mountPath string) error {
21882191
// Act:
@@ -2196,14 +2199,15 @@ func Test_Run_Positive_VolumeMountControllerAttachEnabledRace(t *testing.T) {
21962199
}
21972200

21982201
fakePlugin.WaitForAttachHook = func(spec *volume.Spec, devicePath string, pod *v1.Pod, spectimeout time.Duration) (string, error) {
2202+
defer finishedOnce.Do(func() {
2203+
close(finished)
2204+
})
21992205
// Assert
22002206
// 4. When the volume is mounted again, expect that UnmountDevice operation did not clear devicePath
22012207
if devicePath == "" {
22022208
klog.ErrorS(nil, "Expected WaitForAttach called with devicePath from Node.Status")
2203-
close(finished)
22042209
return "", fmt.Errorf("Expected devicePath from Node.Status")
22052210
}
2206-
close(finished)
22072211
return devicePath, nil
22082212
}
22092213
fakePlugin.Unlock()

0 commit comments

Comments
 (0)