Skip to content

Commit

Permalink
Added ephemeral data check and restructure the code
Browse files Browse the repository at this point in the history
  • Loading branch information
parauliya committed Jan 16, 2020
1 parent 19fb263 commit 8ec0d84
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/actions/action2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM bash
CMD echo '{"action_02": "data_02"}' >> /workflow/data
CMD echo '{"action_02": "data_02"}' > /workflow/data
2 changes: 2 additions & 0 deletions test/build_images.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

docker build -t localhost/action1 actions/action1/
docker build -t localhost/action2 actions/action2/

62 changes: 54 additions & 8 deletions test/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2e

import (
"context"
"fmt"
"os"
"testing"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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")
}
}
}*/
10 changes: 10 additions & 0 deletions test/framework/setup.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package framework

import (
"fmt"
"os"
"os/exec"

"github.com/pkg/errors"
)

func buildCerts(filepath string) error {
Expand Down Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions test/framework/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -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
}
11 changes: 10 additions & 1 deletion test/push_images.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8ec0d84

Please sign in to comment.