From 045ca75c0370030a43302ed510e28cedce548dc5 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Tue, 21 Dec 2021 15:36:44 +0100 Subject: [PATCH] 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. --- .../volume/persistentvolume/pv_controller_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/controller/volume/persistentvolume/pv_controller_test.go b/pkg/controller/volume/persistentvolume/pv_controller_test.go index 0a03cc4dc5b..c12de0d9bb6 100644 --- a/pkg/controller/volume/persistentvolume/pv_controller_test.go +++ b/pkg/controller/volume/persistentvolume/pv_controller_test.go @@ -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)