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

Skip backend integration tests when cli flag isn't passed #527

Merged
merged 4 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
34 changes: 14 additions & 20 deletions backend/test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,13 @@ import (
const (
defaultPageSize = int32(10)
myUploadedPipeline = "my-uploaded-pipeline"
// If true, run as a unit test using a fake client.
// If false, run as an integration test calling the service.
// This is useful to test locally before running an e2e test (which takes a while).
// IMPORTANT: This should always be set to FALSE in the checked-in code.
runAsUnitTest = false
)

func GetRealRootCommand() (*cmd.RootCommand, cmd.ClientFactoryInterface) {
if runAsUnitTest {
return cmd.GetFakeRootCommand()
} else {
clientFactory := cmd.NewClientFactoryWithByteBuffer()
rootCmd := cmd.NewRootCmd(clientFactory)
rootCmd = cmd.CreateSubCommands(rootCmd, defaultPageSize)
return rootCmd, clientFactory
}
clientFactory := cmd.NewClientFactoryWithByteBuffer()
rootCmd := cmd.NewRootCmd(clientFactory)
rootCmd = cmd.CreateSubCommands(rootCmd, defaultPageSize)
return rootCmd, clientFactory
}

type CLIIntegrationTest struct {
Expand All @@ -41,15 +32,18 @@ type CLIIntegrationTest struct {

// Check the cluster namespace has Kubeflow pipelines installed and ready.
func (c *CLIIntegrationTest) SetupTest() {
if *runAsUnitTest {
c.T().SkipNow()
return
}

c.namespace = *namespace

if !runAsUnitTest {
// Wait for the system to be ready.
err := waitForReady(c.namespace, *initializeTimeout)
if err != nil {
glog.Exitf("Cluster namespace '%s' is still not ready after timeout. Error: %s", c.namespace,
err.Error())
}
// Wait for the system to be ready.
err := waitForReady(c.namespace, *initializeTimeout)
if err != nil {
glog.Exitf("Cluster namespace '%s' is still not ready after timeout. Error: %s", c.namespace,
err.Error())
}
}

Expand Down
5 changes: 5 additions & 0 deletions backend/test/experiment_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ type ExperimentApiTest struct {

// Check the namespace have ML job installed and ready
func (s *ExperimentApiTest) SetupTest() {
if *runAsUnitTest {
s.T().SkipNow()
return
}

err := waitForReady(*namespace, *initializeTimeout)
if err != nil {
glog.Exitf("Failed to initialize test. Error: %s", err.Error())
Expand Down
5 changes: 5 additions & 0 deletions backend/test/job_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ type JobApiTestSuite struct {

// Check the namespace have ML pipeline installed and ready
func (s *JobApiTestSuite) SetupTest() {
if *runAsUnitTest {
s.T().SkipNow()
return
}

err := waitForReady(*namespace, *initializeTimeout)
if err != nil {
glog.Exitf("Failed to initialize test. Error: %s", err.Error())
Expand Down
9 changes: 7 additions & 2 deletions backend/test/pipeline_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ type PipelineApiTest struct {

// Check the namespace have ML job installed and ready
func (s *PipelineApiTest) SetupTest() {
if *runAsUnitTest {
s.T().SkipNow()
return
}

err := waitForReady(*namespace, *initializeTimeout)
if err != nil {
glog.Exitf("Failed to initialize test. Error: %s", err.Error())
Expand Down Expand Up @@ -65,7 +70,7 @@ func (s *PipelineApiTest) TestPipelineAPI() {
/* ---------- Import pipeline YAML by URL ---------- */
time.Sleep(1 * time.Second)
sequentialPipeline, err := s.pipelineClient.Create(&params.CreatePipelineParams{
Body: &pipeline_model.APIPipeline{URL:&pipeline_model.APIURL{
Body: &pipeline_model.APIPipeline{URL: &pipeline_model.APIURL{
PipelineURL: "https://storage.googleapis.com/ml-pipeline-dataset/sequential.yaml"}}})
assert.Nil(t, err)
assert.Equal(t, "sequential.yaml", sequentialPipeline.Name)
Expand All @@ -79,7 +84,7 @@ func (s *PipelineApiTest) TestPipelineAPI() {
/* ---------- Import pipeline tarball by URL ---------- */
time.Sleep(1 * time.Second)
argumentUrlPipeline, err := s.pipelineClient.Create(&params.CreatePipelineParams{
Body: &pipeline_model.APIPipeline{URL:&pipeline_model.APIURL{
Body: &pipeline_model.APIPipeline{URL: &pipeline_model.APIURL{
PipelineURL: "https://storage.googleapis.com/ml-pipeline-dataset/arguments.tar.gz"}}})
assert.Nil(t, err)
assert.Equal(t, "arguments.tar.gz", argumentUrlPipeline.Name)
Expand Down
5 changes: 5 additions & 0 deletions backend/test/run_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ type RunApiTestSuite struct {

// Check the namespace have ML pipeline installed and ready
func (s *RunApiTestSuite) SetupTest() {
if *runAsUnitTest {
s.T().SkipNow()
return
}

err := waitForReady(*namespace, *initializeTimeout)
if err != nil {
glog.Exitf("Failed to initialize test. Error: %s", err.Error())
Expand Down
1 change: 1 addition & 0 deletions backend/test/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (

var namespace = flag.String("namespace", "kubeflow", "The namespace ml pipeline deployed to")
var initializeTimeout = flag.Duration("initializeTimeout", 2*time.Minute, "Duration to wait for test initialization")
var runAsUnitTest = flag.Bool("unitTestsOnly", true, "Whether to skip integration tests that call the service")

func waitForReady(namespace string, initializeTimeout time.Duration) error {
var operation = func() error {
Expand Down
2 changes: 1 addition & 1 deletion test/api-integration-test/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST_DIR=backend/test
cd "${BASE_DIR}/${TEST_DIR}"

echo "Run integration test..."
TEST_RESULT=`go test -v ./... -namespace ${NAMESPACE} 2>&1`
TEST_RESULT=`go test -v ./... -namespace ${NAMESPACE} -args -unitTestsOnly=false 2>&1`
TEST_EXIT_CODE=$?

# Log the test result
Expand Down
4 changes: 2 additions & 2 deletions test/backend-unit-test/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cd "${BASE_DIR}/${TEST_DIR}"

# Run test and store the exit code.
echo "Run unit test..."
TEST_RESULT=`go test -v ./... 2>&1`
TEST_RESULT=`go test -v ./... -args -unitTestsOnly=false 2>&1`
yebrahim marked this conversation as resolved.
Show resolved Hide resolved
TEST_EXIT_CODE=$?

# Log the test result
Expand All @@ -62,4 +62,4 @@ printf '%s\n' "$TEST_RESULT" | go-junit-report > ${JUNIT_TEST_RESULT}
echo "Copy test result to GCS ${RESULTS_GCS_DIR}/${JUNIT_TEST_RESULT}"
gsutil cp ${JUNIT_TEST_RESULT} ${RESULTS_GCS_DIR}/${JUNIT_TEST_RESULT}

exit $TEST_EXIT_CODE
exit $TEST_EXIT_CODE