Skip to content

Commit

Permalink
Poll multiple times that the pvc is deleted in TestPipelineRun
Browse files Browse the repository at this point in the history
Let's poll for up to 10mn that the PersistentVolumeClaims has the
DeletionTimestamp set.

Fixes #915

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel committed May 29, 2019
1 parent 30aceb7 commit 4a41fe5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions test/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/tektoncd/pipeline/pkg/artifacts"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/knative/pkg/apis"
knativetest "github.com/knative/pkg/test"
Expand Down Expand Up @@ -175,14 +176,20 @@ func TestPipelineRun(t *testing.T) {
if len(events) != td.expectedNumberOfEvents {
t.Fatalf("Expected %d number of successful events from pipelinerun and taskrun but got %d; list of receieved events : %#v", td.expectedNumberOfEvents, len(events), events)
}
// Check to make sure the PipelineRun's artifact storage PVC has been "deleted" at the end of the run.
pvc, err := c.KubeClient.Kube.CoreV1().PersistentVolumeClaims(namespace).Get(artifacts.GetPVCName(pipelineRun), metav1.GetOptions{})
if err != nil {
if !errors.IsNotFound(err) {
t.Fatalf("Error looking up PVC %s for PipelineRun %s: %s", artifacts.GetPVCName(pipelineRun), prName, err)

// Wait for up to 30 minutes and restart every minute to check if
// the PersistentVolumeClaims has the DeletionTimestamp
if err := wait.PollImmediate(1*time.Minute, 30*time.Minute, func() (bool, error) {
// Check to make sure the PipelineRun's artifact storage PVC has been "deleted" at the end of the run.
pvc, errWait := c.KubeClient.Kube.CoreV1().PersistentVolumeClaims(namespace).Get(artifacts.GetPVCName(pipelineRun), metav1.GetOptions{})
if errWait != nil && !errors.IsNotFound(errWait) {
return true, fmt.Errorf("Error looking up PVC %s for PipelineRun %s: %s", artifacts.GetPVCName(pipelineRun), prName, errWait)
}
} else if pvc.DeletionTimestamp == nil {
t.Fatalf("PVC %s still exists after PipelineRun %s has completed: %v", artifacts.GetPVCName(pipelineRun), prName, pvc)
return pvc.DeletionTimestamp == nil, nil
}); err != nil {
// getting the PVC again so we can get more information about it
pvc, _ := c.KubeClient.Kube.CoreV1().PersistentVolumeClaims(namespace).Get(artifacts.GetPVCName(pipelineRun), metav1.GetOptions{})
t.Fatalf("Error while waiting for the PVC to be set as deleted: %s: %s: %s %v", artifacts.GetPVCName(pipelineRun), err, prName, pvc)
}
t.Logf("Successfully finished test %q", td.name)
})
Expand Down

0 comments on commit 4a41fe5

Please sign in to comment.