From 37b20f0116d2800333cb1eb2e986ba478b77b091 Mon Sep 17 00:00:00 2001 From: Yecheng Fu Date: Thu, 22 Nov 2018 13:39:51 +0800 Subject: [PATCH] refactor volume binding stress tests to test scheduling one pod repeatedly this helps to detect races between Find/Assume and Bind volumes --- .../scheduler/volume_binding_test.go | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/integration/scheduler/volume_binding_test.go b/test/integration/scheduler/volume_binding_test.go index 80cc3d85a4..5d89a97346 100644 --- a/test/integration/scheduler/volume_binding_test.go +++ b/test/integration/scheduler/volume_binding_test.go @@ -389,7 +389,7 @@ func TestVolumeBindingRescheduling(t *testing.T) { } } -// TestVolumeBindingStress creates pods, each with unbound PVCs. +// TestVolumeBindingStress creates pods, each with unbound or prebound PVCs. // PVs are precreated. func TestVolumeBindingStress(t *testing.T) { testVolumeBindingStress(t, 0, false, 0) @@ -441,16 +441,31 @@ func testVolumeBindingStress(t *testing.T, schedulerResyncPeriod time.Duration, pvs := []*v1.PersistentVolume{} pvcs := []*v1.PersistentVolumeClaim{} for i := 0; i < podLimit*volsPerPod; i++ { + var ( + pv *v1.PersistentVolume + pvc *v1.PersistentVolumeClaim + pvName = fmt.Sprintf("pv-stress-%v", i) + pvcName = fmt.Sprintf("pvc-stress-%v", i) + ) // Don't create pvs for dynamic provisioning test if !dynamic { - pv := makePV(fmt.Sprintf("pv-stress-%v", i), *scName, "", "", node1) + if rand.Int()%2 == 0 { + // static unbound pvs + pv = makePV(pvName, *scName, "", "", node1) + } else { + // static prebound pvs + pv = makePV(pvName, classImmediate, pvcName, config.ns, node1) + } if pv, err := config.client.CoreV1().PersistentVolumes().Create(pv); err != nil { t.Fatalf("Failed to create PersistentVolume %q: %v", pv.Name, err) } pvs = append(pvs, pv) } - - pvc := makePVC(fmt.Sprintf("pvc-stress-%v", i), config.ns, scName, "") + if pv != nil && pv.Spec.ClaimRef != nil && pv.Spec.ClaimRef.Name == pvcName { + pvc = makePVC(pvcName, config.ns, &classImmediate, pv.Name) + } else { + pvc = makePVC(pvcName, config.ns, scName, "") + } if pvc, err := config.client.CoreV1().PersistentVolumeClaims(config.ns).Create(pvc); err != nil { t.Fatalf("Failed to create PersistentVolumeClaim %q: %v", pvc.Name, err) }