mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
Fix(kubelet/test): flaky TestWaitForAllPodsUnmount by adding goroutine synchronization
This commit is contained in:
@@ -516,7 +516,6 @@ func (vm *volumeManager) WaitForAllPodsUnmount(ctx context.Context, pods []*v1.P
|
||||
|
||||
funcs := make([]func() error, 0, len(pods))
|
||||
for _, pod := range pods {
|
||||
pod := pod
|
||||
funcs = append(funcs, func() error {
|
||||
return vm.WaitForUnmount(ctx, pod)
|
||||
})
|
||||
|
||||
@@ -686,8 +686,8 @@ func TestWaitForAllPodsUnmount(t *testing.T) {
|
||||
expectedError: true,
|
||||
},
|
||||
{
|
||||
name: "concurrent unmount - many pods (50) with timeout errors",
|
||||
numPods: 50,
|
||||
name: "concurrent unmount - many pods (20) with timeout errors",
|
||||
numPods: 20,
|
||||
podMode: v1.PersistentVolumeFilesystem,
|
||||
expectedError: true,
|
||||
},
|
||||
@@ -725,9 +725,34 @@ func TestWaitForAllPodsUnmount(t *testing.T) {
|
||||
go simulateVolumeInUseUpdate(volumeName, ctx.Done(), manager)
|
||||
}
|
||||
|
||||
volumeMarkTimeout := 10*time.Second + time.Duration(test.numPods/10)*5*time.Second
|
||||
err := wait.PollUntilContextTimeout(ctx, 50*time.Millisecond, volumeMarkTimeout, true, func(context.Context) (bool, error) {
|
||||
inUseVolumes := manager.GetVolumesInUse()
|
||||
return len(inUseVolumes) == test.numPods, nil
|
||||
})
|
||||
|
||||
require.NoError(t, err, "Timeout waiting for all %d volumes to be marked as in-use", test.numPods)
|
||||
|
||||
type attachResult struct {
|
||||
podName string
|
||||
err error
|
||||
}
|
||||
resultChan := make(chan attachResult, test.numPods)
|
||||
|
||||
for _, pod := range pods {
|
||||
err := manager.WaitForAttachAndMount(ctx, pod)
|
||||
require.NoError(t, err, "Failed to wait for attach and mount for pod %s", pod.Name)
|
||||
go func() {
|
||||
err := manager.WaitForAttachAndMount(context.Background(), pod)
|
||||
resultChan <- attachResult{
|
||||
podName: pod.Name,
|
||||
err: err,
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
for i := 0; i < test.numPods; i++ {
|
||||
result := <-resultChan
|
||||
require.NoError(t, result.err,
|
||||
"Failed to wait for attach and mount for pod %s", result.podName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user