mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 20:42:26 +00:00
test flake: fix data race in csi_test.go
The attach goroutine can currently t.Log/t.Error during or after the
subtest completion. This causes races like:
```
==================
WARNING: DATA RACE
Read at 0x00c000e90ac3 by goroutine 1231:
testing.(*common).logDepth()
GOROOT/src/testing/testing.go:736 +0xa9
testing.(*common).log()
GOROOT/src/testing/testing.go:729 +0x8f
testing.(*common).Logf()
GOROOT/src/testing/testing.go:775 +0x21
k8s.io/kubernetes/pkg/volume/csi.TestCSI_VolumeAll.func21.1()
pkg/volume/csi/csi_test.go:313 +0x1a4
Previous write at 0x00c000e90ac3 by goroutine 875:
testing.tRunner.func1()
GOROOT/src/testing/testing.go:1113 +0x484
testing.tRunner()
GOROOT/src/testing/testing.go:1131 +0x22a
testing.tRunner()
GOROOT/src/testing/testing.go:1127 +0x202
Goroutine 1231 (running) created at:
k8s.io/kubernetes/pkg/volume/csi.TestCSI_VolumeAll.func21()
pkg/volume/csi/csi_test.go:307 +0xf05
testing.tRunner()
GOROOT/src/testing/testing.go:1127 +0x202
Goroutine 875 (running) created at:
testing.(*T).Run()
GOROOT/src/testing/testing.go:1178 +0x796
k8s.io/kubernetes/pkg/volume/csi.TestCSI_VolumeAll()
pkg/volume/csi/csi_test.go:223 +0xb2c
testing.tRunner()
GOROOT/src/testing/testing.go:1127 +0x202
==================
```
See also this comment:
07c1788357/src/testing/testing.go (L1141-L1142)
Noticed in:
https://github.com/kubernetes/kubernetes/pull/94449
https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/94449/pull-kubernetes-bazel-test/1304519003330318337
This commit is contained in:
parent
1b8c7585f3
commit
94f4f06d13
@ -304,19 +304,22 @@ func TestCSI_VolumeAll(t *testing.T) {
|
||||
}
|
||||
|
||||
// creates VolumeAttachment and blocks until it is marked attached (done by external attacher)
|
||||
go func(spec *volume.Spec, nodeName types.NodeName) {
|
||||
attachID, err := volAttacher.Attach(spec, nodeName)
|
||||
attachDone := make(chan struct{})
|
||||
go func() {
|
||||
defer close(attachDone)
|
||||
attachID, err := volAttacher.Attach(volSpec, host.GetNodeName())
|
||||
if err != nil {
|
||||
t.Errorf("csiTest.VolumeAll attacher.Attach failed: %s", err)
|
||||
return
|
||||
}
|
||||
t.Logf("csiTest.VolumeAll got attachID %s", attachID)
|
||||
|
||||
}(volSpec, host.GetNodeName())
|
||||
}()
|
||||
|
||||
// Simulates external-attacher and marks VolumeAttachment.Status.Attached = true
|
||||
markVolumeAttached(t, host.GetKubeClient(), fakeWatcher, attachName, storage.VolumeAttachmentStatus{Attached: true})
|
||||
<-attachDone
|
||||
|
||||
// Observe attach on this node.
|
||||
devicePath, err = volAttacher.WaitForAttach(volSpec, "", pod, 500*time.Millisecond)
|
||||
if err != nil {
|
||||
t.Fatal("csiTest.VolumeAll attacher.WaitForAttach failed:", err)
|
||||
|
Loading…
Reference in New Issue
Block a user