From 8ec0d84b87bd1f291640a46b1e262d24c1c3c5a2 Mon Sep 17 00:00:00 2001 From: parauliya Date: Thu, 16 Jan 2020 16:37:50 +0530 Subject: [PATCH] Added ephemeral data check and restructure the code --- Makefile | 3 +- test/actions/action2/Dockerfile | 2 +- test/build_images.sh | 2 ++ test/e2e_test.go | 62 ++++++++++++++++++++++++++++----- test/framework/setup.go | 10 ++++++ test/framework/worker.go | 13 ++----- test/push_images.sh | 11 +++++- 7 files changed, 82 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 1d31b8761..21a803ac9 100644 --- a/Makefile +++ b/Makefile @@ -22,4 +22,5 @@ run: ${binaries} docker-compose up -d --build db docker-compose up --build server cli test: - go test -race -coverprofile=coverage.txt -covermode=atomic ${TEST_ARGS} ./... + go clean -testcache + go test ./test -v diff --git a/test/actions/action2/Dockerfile b/test/actions/action2/Dockerfile index 918e8cf64..5ba04d78c 100644 --- a/test/actions/action2/Dockerfile +++ b/test/actions/action2/Dockerfile @@ -1,2 +1,2 @@ FROM bash -CMD echo '{"action_02": "data_02"}' >> /workflow/data +CMD echo '{"action_02": "data_02"}' > /workflow/data diff --git a/test/build_images.sh b/test/build_images.sh index ebc40e0f6..1b5d28fed 100755 --- a/test/build_images.sh +++ b/test/build_images.sh @@ -1,3 +1,5 @@ +#!/bin/bash + docker build -t localhost/action1 actions/action1/ docker build -t localhost/action2 actions/action2/ diff --git a/test/e2e_test.go b/test/e2e_test.go index 98aea636a..de59b1b27 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -1,6 +1,7 @@ package e2e import ( + "context" "fmt" "os" "testing" @@ -47,20 +48,22 @@ func TestMain(m *testing.M) { } var testCases = []struct { - name string + //name string target string template string workers int64 expected workflow.ActionState + ephData string }{ - {"OneWorkerTest", "target_1.json", "sample_1", 1, workflow.ActionState_ACTION_SUCCESS}, + {"target_1.json", "sample_1", 1, workflow.ActionState_ACTION_SUCCESS, `{"action_02": "data_02}`}, + {"target_1.json", "sample_2", 2, workflow.ActionState_ACTION_SUCCESS, ""}, } -func TestRover(t *testing.T) { +func TestOneWorker(t *testing.T) { // Start test - for _, test := range testCases { - fmt.Printf("Starting %s\n", test.name) + if len(testCases) > 0 { + test := testCases[0] wfID, err := framework.SetupWorkflow(test.target, test.template) if err != nil { @@ -72,7 +75,49 @@ func TestRover(t *testing.T) { workerStatus := make(chan int64, test.workers) wfStatus, err := framework.StartWorkers(test.workers, workerStatus, wfID) if err != nil { - fmt.Printf("Test : %s : Failed\n", test.name) + fmt.Printf("Test Failed\n") + t.Error(err) + } + assert.Equal(t, test.expected, wfStatus) + assert.NoError(t, err, "Workers Failed") + + for i := int64(0); i < test.workers; i++ { + if len(workerStatus) > 0 { + //Check for worker exit status + status := <-workerStatus + expected := 0 + if test.expected != workflow.ActionState_ACTION_SUCCESS { + expected = 1 + } + assert.Equal(t, int64(expected), status) + //checking for ephemeral data validation + resp, err := client.WorkflowClient.GetWorkflowData(context.Background(), &workflow.GetWorkflowDataRequest{WorkflowID: wfID, Version: 0}) + if err != nil { + assert.Equal(t, test.ephData, string(resp.GetData())) + } + } + } + } +} + +/* +func TestTwoWorker(t *testing.T) { + // Start test + if len(testCases) > 1 { + test := testCases[1] + fmt.Printf("Starting Test") + wfID, err := framework.SetupWorkflow(test.target, test.template) + + if err != nil { + t.Error(err) + } + assert.NoError(t, err, "Create Workflow") + + // Start the Worker + workerStatus := make(chan int64, test.workers) + wfStatus, err := framework.StartWorkers(test.workers, workerStatus, wfID) + if err != nil { + fmt.Printf("Test Failed\n") t.Error(err) } assert.Equal(t, test.expected, wfStatus) @@ -90,6 +135,7 @@ func TestRover(t *testing.T) { assert.Equal(t, int64(expected), status) } } - fmt.Printf("Test : %s : Passed\n", test.name) + fmt.Printf("Test Passed\n") } -} + +}*/ diff --git a/test/framework/setup.go b/test/framework/setup.go index e8ef39f9d..1ca50fa3b 100644 --- a/test/framework/setup.go +++ b/test/framework/setup.go @@ -1,8 +1,11 @@ package framework import ( + "fmt" "os" "os/exec" + + "github.com/pkg/errors" ) func buildCerts(filepath string) error { @@ -80,6 +83,13 @@ func StartStack() error { return err } + //Create Worker image locally + err = createWorkerImage() + if err != nil { + fmt.Println("failed to create worker Image") + return errors.Wrap(err, "worker image creation failed") + } + // Start other containers cmd := exec.Command("/bin/sh", "-c", "docker-compose -f "+filepath+" up --build -d") cmd.Stdout = os.Stdout diff --git a/test/framework/worker.go b/test/framework/worker.go index 8d512c080..9dac17a1d 100644 --- a/test/framework/worker.go +++ b/test/framework/worker.go @@ -110,12 +110,6 @@ func StartWorkers(workers int64, workerStatus chan<- int64, wfID string) (workfl return workflow.ActionState_ACTION_FAILED, err } workerContainer := make([]string, workers) - //create worker image locally: - err = createWorkerImage() - if err != nil { - fmt.Println("failed to create worker Image") - return workflow.ActionState_ACTION_FAILED, errors.Wrap(err, "worker image creation failed") - } var i int64 for i = 0; i < workers; i++ { ctx := context.Background() @@ -133,7 +127,7 @@ func StartWorkers(workers int64, workerStatus chan<- int64, wfID string) (workfl if err != nil { fmt.Println("Worker with id ", cID, " failed to start: ", err) - // TODO Should be remove the containers which started previously + // TODO Should be remove the containers which started previously? } else { fmt.Println("Worker started with ID : ", cID) wg.Add(1) @@ -149,9 +143,9 @@ func StartWorkers(workers int64, workerStatus chan<- int64, wfID string) (workfl status := <-workflowStatus fmt.Println("Status of Workflow : ", status) wg.Wait() - //ctx := context.Background() + ctx := context.Background() for _, cID := range workerContainer { - //err := removeContainer(ctx, cli, cID) + err := removeContainer(ctx, cli, cID) if err != nil { fmt.Println("Failed to remove worker container with ID : ", cID) } @@ -175,6 +169,5 @@ func StartWorkers(workers int64, workerStatus chan<- int64, wfID string) (workfl if err != nil { return status, err } - fmt.Println("Test Passed") return status, nil } diff --git a/test/push_images.sh b/test/push_images.sh index 952ebe0f6..4b67e1d13 100755 --- a/test/push_images.sh +++ b/test/push_images.sh @@ -1,3 +1,12 @@ -docker login -u username -p password localhost +#!/bin/bash + +for i in {1..10} +do + docker login -u username -p password localhost + if [ $? -eq 0 ]; then + break + fi + sleep 1 +done docker push localhost/action1 docker push localhost/action2