mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #93673 from zhouya0/pv_controller_test_add_time_out
Cleanup wait forever loops in pv_controller_test.go
This commit is contained in:
commit
5ce93a2ab5
@ -129,8 +129,11 @@ func TestControllerSync(t *testing.T) {
|
||||
obj := ctrl.claims.List()[0]
|
||||
claim := obj.(*v1.PersistentVolumeClaim)
|
||||
reactor.DeleteClaimEvent(claim)
|
||||
for len(ctrl.claims.ListKeys()) > 0 {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
err := wait.Poll(10*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
|
||||
return len(ctrl.claims.ListKeys()) == 0, nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// claim has been removed from controller's cache, generate a volume deleted event
|
||||
volume := ctrl.volumes.store.List()[0].(*v1.PersistentVolume)
|
||||
@ -158,8 +161,11 @@ func TestControllerSync(t *testing.T) {
|
||||
claim := obj.(*v1.PersistentVolumeClaim)
|
||||
reactor.DeleteClaimEvent(claim)
|
||||
// wait until claim is cleared from cache, i.e., deleteClaim is called
|
||||
for len(ctrl.claims.ListKeys()) > 0 {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
err := wait.Poll(10*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
|
||||
return len(ctrl.claims.ListKeys()) == 0, nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// wait for volume delete operation to appear once volumeWorker() runs
|
||||
return wait.PollImmediate(10*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
|
||||
@ -188,16 +194,22 @@ func TestControllerSync(t *testing.T) {
|
||||
func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error {
|
||||
volume := ctrl.volumes.store.List()[0].(*v1.PersistentVolume)
|
||||
reactor.DeleteVolumeEvent(volume)
|
||||
for len(ctrl.volumes.store.ListKeys()) > 0 {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
err := wait.Poll(10*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
|
||||
return len(ctrl.volumes.store.ListKeys()) == 0, nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// trying to remove the claim as well
|
||||
obj := ctrl.claims.List()[0]
|
||||
claim := obj.(*v1.PersistentVolumeClaim)
|
||||
reactor.DeleteClaimEvent(claim)
|
||||
// wait until claim is cleared from cache, i.e., deleteClaim is called
|
||||
for len(ctrl.claims.ListKeys()) > 0 {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
err = wait.Poll(10*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
|
||||
return len(ctrl.claims.ListKeys()) == 0, nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// make sure operation timestamp cache is empty
|
||||
if ctrl.operationTimestamps.Has("volume5-7") {
|
||||
@ -220,16 +232,22 @@ func TestControllerSync(t *testing.T) {
|
||||
// "deleteClaim" to remove the claim from controller's cache and mark bound volume to be released
|
||||
func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error {
|
||||
// wait until the provision timestamp has been inserted
|
||||
for !ctrl.operationTimestamps.Has("default/claim5-8") {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
err := wait.Poll(10*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
|
||||
return ctrl.operationTimestamps.Has("default/claim5-8"), nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// delete the claim
|
||||
obj := ctrl.claims.List()[0]
|
||||
claim := obj.(*v1.PersistentVolumeClaim)
|
||||
reactor.DeleteClaimEvent(claim)
|
||||
// wait until claim is cleared from cache, i.e., deleteClaim is called
|
||||
for len(ctrl.claims.ListKeys()) > 0 {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
err = wait.Poll(10*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
|
||||
return len(ctrl.claims.ListKeys()) == 0, nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// make sure operation timestamp cache is empty
|
||||
if ctrl.operationTimestamps.Has("default/claim5-8") {
|
||||
@ -307,12 +325,14 @@ func TestControllerSync(t *testing.T) {
|
||||
go ctrl.Run(stopCh)
|
||||
|
||||
// Wait for the controller to pass initial sync and fill its caches.
|
||||
for !ctrl.volumeListerSynced() ||
|
||||
!ctrl.claimListerSynced() ||
|
||||
len(ctrl.claims.ListKeys()) < len(test.initialClaims) ||
|
||||
len(ctrl.volumes.store.ListKeys()) < len(test.initialVolumes) {
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
err = wait.Poll(10*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
|
||||
return ctrl.volumeListerSynced() &&
|
||||
ctrl.claimListerSynced() &&
|
||||
len(ctrl.claims.ListKeys()) >= len(test.initialClaims) &&
|
||||
len(ctrl.volumes.store.ListKeys()) >= len(test.initialVolumes), nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("Test %q controller sync failed: %v", test.name, err)
|
||||
}
|
||||
klog.V(4).Infof("controller synced, starting test")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user