Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed flaky test IntegrationTestSuite#TestPipelineSuccessfulRun #658

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading