Deflake PV metrics unit test

Test 5-7 tries to delete a PVC at the very same time when it detects that
the PV controller started processing the PVC. The controller then sometimes
can't update the PVC and generate an event for it that the test expects.

From PV controller logs (not shown in CI):
> I1221 14:36:34.548160  104481 pv_controller.go:815] updating PersistentVolumeClaim[default/claim5-7] status: set phase Lost failed: cannot update claim claim5-7: claim not found

Typical error in CI:
> FAIL: TestControllerSync (83.22s)
> framework_test.go:202: Event "Warning ClaimLost" not emitted

Therefore wait for the PVC to be fully processed before deleting the PVC to
avoid races.
This commit is contained in:
Jan Safranek 2021-12-21 15:36:44 +01:00
parent e323306ce0
commit 045ca75c03

View File

@ -225,6 +225,18 @@ func TestControllerSync(t *testing.T) {
if err != nil {
return err
}
// Wait for the PVC to get fully processed. This avoids races between PV controller and DeleteClaimEvent
// below.
err = wait.Poll(10*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
obj := ctrl.claims.List()[0]
claim := obj.(*v1.PersistentVolumeClaim)
return claim.Status.Phase == v1.ClaimLost, nil
})
if err != nil {
return err
}
// trying to remove the claim as well
obj := ctrl.claims.List()[0]
claim := obj.(*v1.PersistentVolumeClaim)