Skip to content

Commit

Permalink
Fix flacky Affinity Assistant test
Browse files Browse the repository at this point in the history
Prior to this commit, the `TestAffinityAssistant_PerWorkspace` integration test validates the lifecycle status of the
Affinity Assistant `StatefulSet` of the `pipeleinrun` when it is created and completed. However, the `StatefulSet` cannot be
created (and deleted) immediately after the `pipelinerun` is created (and completed) due to API latency, which makes the test flacky
(see [example](https://prow.tekton.dev/view/gs/tekton-prow/pr-logs/pull/tektoncd_pipeline/6921/pull-tekton-pipeline-integration-tests/1679203026977427456)).

This commit removes statefulset status check in the integration test. This functionality is covered in the [unit test](https://github.com/tektoncd/pipeline/blob/b769b5620300d7fb6d6638083124d03636caa503/pkg/reconciler/pipelinerun/affinity_assistant_test.go#L188).

/kind bug
QuanZhang-William authored and tekton-robot committed Jul 14, 2023
1 parent 7ab37a1 commit 9c249d6
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions test/affinity_assistant_test.go
Original file line number Diff line number Diff line change
@@ -24,15 +24,12 @@ import (
"fmt"
"testing"

"github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun"
"github.com/tektoncd/pipeline/test/parse"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
knativetest "knative.dev/pkg/test"
)

// TestAffinityAssistant_PerWorkspace tests the lifecycle status of Affinity Assistant and PVCs
// from the start to the deletion of a PipelineRun
// TestAffinityAssistant_PerWorkspace tests the taskrun pod scheduling and the PVC lifecycle status
func TestAffinityAssistant_PerWorkspace(t *testing.T) {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
@@ -79,17 +76,14 @@ spec:
if _, err := c.V1PipelineRunClient.Create(ctx, pr, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create PipelineRun: %s", err)
}
t.Logf("Waiting for PipelineRun in namespace %s to run", namespace)
if err := WaitForPipelineRunState(ctx, c, prName, timeout, Running(prName), "PipelineRun Running", v1Version); err != nil {
t.Fatalf("Error waiting for PipelineRun to run: %s", err)
}

// validate SS and PVC are created
ssName := pipelinerun.GetAffinityAssistantName("my-workspace", pr.Name)
ss, err := c.KubeClient.AppsV1().StatefulSets(namespace).Get(ctx, ssName, metav1.GetOptions{})
if err != nil {
t.Fatalf("Couldn't get expected Affinity Assistant StatefulSet %s, err: %s", ss, err)
// wait for PipelineRun to finish
t.Logf("Waiting for PipelineRun in namespace %s to finish", namespace)
if err := WaitForPipelineRunState(ctx, c, prName, timeout, PipelineRunSucceed(prName), "PipelineRunSucceeded", v1Version); err != nil {
t.Errorf("Error waiting for PipelineRun to finish: %s", err)
}

// get PVC
pvcList, err := c.KubeClient.CoreV1().PersistentVolumeClaims(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
t.Fatalf("Couldn't get expected PVCs: %s", err)
@@ -99,18 +93,6 @@ spec:
}
pvcName := pvcList.Items[0].Name

// wait for PipelineRun to finish
t.Logf("Waiting for PipelineRun in namespace %s to finish", namespace)
if err := WaitForPipelineRunState(ctx, c, prName, timeout, PipelineRunSucceed(prName), "PipelineRunSucceeded", v1Version); err != nil {
t.Errorf("Error waiting for PipelineRun to finish: %s", err)
}

// validate Affinity Assistant is cleaned up
ss, err = c.KubeClient.AppsV1().StatefulSets(namespace).Get(ctx, ssName, metav1.GetOptions{})
if !apierrors.IsNotFound(err) {
t.Fatalf("Failed to cleanup Affinity Assistant StatefulSet: %v, err: %v", ssName, err)
}

// validate PipelineRun pods sharing the same PVC are scheduled to the same node
podFoo, err := c.KubeClient.CoreV1().Pods(namespace).Get(ctx, fmt.Sprintf("%v-foo-pod", prName), metav1.GetOptions{})
if err != nil {

0 comments on commit 9c249d6

Please sign in to comment.