From 5fe2b21a474aa19766f9ae067133e413ac263cab Mon Sep 17 00:00:00 2001 From: hbelmiro Date: Wed, 12 Jun 2024 11:42:35 -0300 Subject: [PATCH] Fixed flaky test IntegrationTestSuite#TestPipelineSuccessfulRun Signed-off-by: hbelmiro --- tests/README.md | 2 +- tests/pipeline_runs_test.go | 11 ++++++----- tests/util/rest.go | 19 +++++++++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/README.md b/tests/README.md index ef7c2ae32..294d6b244 100644 --- a/tests/README.md +++ b/tests/README.md @@ -50,7 +50,7 @@ go test ./... --tags=test_integration -v \ -kubeconfig=${KUBECONFIG_PATH} \ -k8sApiServerHost=${TARGET_CLUSTER} \ -DSPANamespace=${TARGET_NAMESPACE} \ - -DSPAPath=resources/dspa-lite.yaml + -DSPAPath=resources/dspa-lite.yaml \ -skipDeploy=true \ -skipCleanup=true ``` diff --git a/tests/pipeline_runs_test.go b/tests/pipeline_runs_test.go index 529b74377..8e32484ec 100644 --- a/tests/pipeline_runs_test.go +++ b/tests/pipeline_runs_test.go @@ -26,7 +26,6 @@ import ( "testing" TestUtil "github.com/opendatahub-io/data-science-pipelines-operator/tests/util" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -35,7 +34,8 @@ func (suite *IntegrationTestSuite) TestPipelineSuccessfulRun() { suite.T().Run("Should create a Pipeline Run", func(t *testing.T) { // Retrieve Pipeline ID to create a new run pipelineDisplayName := "[Demo] iris-training" - pipelineID := TestUtil.RetrievePipelineId(t, APIServerURL, pipelineDisplayName) + pipelineID, err := TestUtil.RetrievePipelineId(t, APIServerURL, pipelineDisplayName) + require.NoError(t, err) postUrl := fmt.Sprintf("%s/apis/v2beta1/runs", APIServerURL) body := TestUtil.FormatRequestBody(t, pipelineID, pipelineDisplayName) contentType := "application/json" @@ -46,7 +46,7 @@ func (suite *IntegrationTestSuite) TestPipelineSuccessfulRun() { responseString := string(responseData) loggr.Info(responseString) require.NoError(t, err) - assert.Equal(t, 200, response.StatusCode) + require.Equal(t, 200, response.StatusCode) err = TestUtil.WaitForPipelineRunCompletion(t, APIServerURL) require.NoError(t, err) @@ -55,7 +55,8 @@ func (suite *IntegrationTestSuite) TestPipelineSuccessfulRun() { suite.T().Run("Should create a Pipeline Run using custom pip server", func(t *testing.T) { // Retrieve Pipeline ID to create a new run pipelineDisplayName := "Test pipeline run with custom pip server" - pipelineID := TestUtil.RetrievePipelineId(t, APIServerURL, pipelineDisplayName) + pipelineID, err := TestUtil.RetrievePipelineId(t, APIServerURL, pipelineDisplayName) + require.NoError(t, err) postUrl := fmt.Sprintf("%s/apis/v2beta1/runs", APIServerURL) body := TestUtil.FormatRequestBody(t, pipelineID, pipelineDisplayName) contentType := "application/json" @@ -66,7 +67,7 @@ func (suite *IntegrationTestSuite) TestPipelineSuccessfulRun() { responseString := string(responseData) loggr.Info(responseString) require.NoError(t, err) - assert.Equal(t, 200, response.StatusCode) + require.Equal(t, 200, response.StatusCode) err = TestUtil.WaitForPipelineRunCompletion(t, APIServerURL) require.NoError(t, err) diff --git a/tests/util/rest.go b/tests/util/rest.go index c71d1842f..4ce9f1714 100644 --- a/tests/util/rest.go +++ b/tests/util/rest.go @@ -16,6 +16,7 @@ package testUtil import ( "bytes" "encoding/json" + "errors" "fmt" "io" "mime/multipart" @@ -70,22 +71,27 @@ func FormFromFile(t *testing.T, form map[string]string) (*bytes.Buffer, string) return body, mp.FormDataContentType() } -func RetrievePipelineId(t *testing.T, APIServerURL string, PipelineDisplayName string) string { +func RetrievePipelineId(t *testing.T, APIServerURL string, PipelineDisplayName string) (string, error) { response, err := http.Get(fmt.Sprintf("%s/apis/v2beta1/pipelines", APIServerURL)) require.NoError(t, err) responseData, err := io.ReadAll(response.Body) require.NoError(t, err) var pipelineData Pipeline - var pipelineID string + var pipelineID *string err = json.Unmarshal(responseData, &pipelineData) require.NoError(t, err) for _, pipeline := range pipelineData.Pipelines { if pipeline.DisplayName == PipelineDisplayName { - pipelineID = pipeline.PipelineID + pipelineID = &pipeline.PipelineID break } } - return pipelineID + + if pipelineID != nil { + return *pipelineID, nil + } else { + return "", errors.New("pipeline not found") + } } func FormatRequestBody(t *testing.T, pipelineID string, PipelineDisplayName string) []byte { @@ -133,6 +139,11 @@ func CheckPipelineRunStatus(t *testing.T, APIServerURL string) (string, error) { err = json.Unmarshal(responseData, &data) require.NoError(t, err) + if data["runs"] == nil { + // No runs found + return "", nil + } + // Extracting the Run state runs := data["runs"].([]interface{}) for _, run := range runs {