Skip to content

Commit

Permalink
Merge pull request #658 from hbelmiro/RHOAIENG-7657
Browse files Browse the repository at this point in the history
Fixed flaky test IntegrationTestSuite#TestPipelineSuccessfulRun
  • Loading branch information
openshift-merge-bot[bot] authored Jun 20, 2024
2 parents 6d8fd01 + 5fe2b21 commit c9eefa6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
11 changes: 6 additions & 5 deletions tests/pipeline_runs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -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"
Expand All @@ -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)
Expand Down
19 changes: 15 additions & 4 deletions tests/util/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package testUtil
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"mime/multipart"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c9eefa6

Please sign in to comment.