Skip to content

Commit

Permalink
Fixed flaky test IntegrationTestSuite#TestPipelineSuccessfulRun
Browse files Browse the repository at this point in the history
Signed-off-by: hbelmiro <helber.belmiro@gmail.com>
  • Loading branch information
hbelmiro committed Jun 18, 2024
1 parent 6d8fd01 commit 93b641f
Show file tree
Hide file tree
Showing 3 changed files with 54 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
43 changes: 38 additions & 5 deletions tests/pipeline_runs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,48 @@ import (
"testing"

TestUtil "github.com/opendatahub-io/data-science-pipelines-operator/tests/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

//func TestRun(t *testing.T) {
// APIServerURL = "https://ds-pipeline-sample-kubeflow.apps.hbelmiro-2.dev.datahub.redhat.com"
// http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
//
// // Retrieve Pipeline ID to create a new run
// pipelineDisplayName := "[Demo] iris-training"
// 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"
// // Create a new run
// req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(body))
// if err != nil {
// require.NoError(t, err)
// }
// req.Header.Set("Authorization", "Bearer sha256~ZmtcUyTktM2e-PUhV1tDfOt7BCUg82_BpdTqURrr4Po")
//
// // Set content type header
// req.Header.Set("Content-Type", contentType)
//
// // Send request
// client := http.DefaultClient
// response, err := client.Do(req)
// require.NoError(t, err)
// responseData, err := io.ReadAll(response.Body)
// responseString := string(responseData)
// loggr.Info(responseString)
// require.NoError(t, err)
// require.Equal(t, 200, response.StatusCode)
//}

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 +78,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 +87,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 +99,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 93b641f

Please sign in to comment.