From 8d64db5b802bd235db17deb03bf53fbe3004b11f Mon Sep 17 00:00:00 2001 From: parauliya Date: Wed, 19 Aug 2020 11:57:24 +0530 Subject: [PATCH] Added test cases for the scenario where there are two successfull workflows for one worker Signed-off-by: parauliya --- test/_vagrant/hello-world-again.tmpl | 10 ++ test/_vagrant/vagrant_test.go | 153 +++++++++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 test/_vagrant/hello-world-again.tmpl diff --git a/test/_vagrant/hello-world-again.tmpl b/test/_vagrant/hello-world-again.tmpl new file mode 100644 index 000000000..2e660d451 --- /dev/null +++ b/test/_vagrant/hello-world-again.tmpl @@ -0,0 +1,10 @@ +version: "0.1" +name: hello_world_again_workflow +global_timeout: 600 +tasks: + - name: "hello world" + worker: "{{.device_1}}" + actions: + - name: "hello_world_again" + image: hello-world-again + timeout: 60 diff --git a/test/_vagrant/vagrant_test.go b/test/_vagrant/vagrant_test.go index e6045c30d..ab2b38347 100644 --- a/test/_vagrant/vagrant_test.go +++ b/test/_vagrant/vagrant_test.go @@ -402,6 +402,159 @@ func TestOneFailedWorkflow(t *testing.T) { t.Fatal("Workflow never got to a complite state or it didn't make it on time (5m)") } +func TestTwoSuccessfullWorkflows(t *testing.T) { + ctx := context.Background() + + machine, err := vagrant.Up(ctx, + vagrant.WithLogger(t.Logf), + vagrant.WithMachineName("provisioner"), + vagrant.WithWorkdir("../../deploy/vagrant"), + ) + if err != nil { + t.Fatal(err) + } + + defer func() { + err := machine.Destroy(ctx) + if err != nil { + t.Error(err) + } + }() + + _, err = machine.Exec(ctx, "cd /vagrant/deploy && source ../envrc && docker-compose up -d") + if err != nil { + t.Fatal(err) + } + + _, err = machine.Exec(ctx, "docker pull hello-world") + if err != nil { + t.Fatal(err) + } + + _, err = machine.Exec(ctx, "docker tag hello-world 192.168.1.1/hello-world") + if err != nil { + t.Fatal(err) + } + + _, err = machine.Exec(ctx, "docker push 192.168.1.1/hello-world") + if err != nil { + t.Fatal(err) + } + + _, err = machine.Exec(ctx, "docker tag hello-world 192.168.1.1/hello-world-again") + if err != nil { + t.Fatal(err) + } + + _, err = machine.Exec(ctx, "docker push 192.168.1.1/hello-world-again") + if err != nil { + t.Fatal(err) + } + + for ii := 0; ii < 5; ii++ { + resp, err := http.Get("http://localhost:42114/_packet/healthcheck") + if err != nil || resp.StatusCode != http.StatusOK { + if err != nil { + t.Logf("err tinkerbell healthcheck... retrying: %s", err) + } else { + t.Logf("err tinkerbell healthcheck... expected status code 200 got %d retrying", resp.StatusCode) + } + time.Sleep(10 * time.Second) + } + } + + t.Log("Tinkerbell is up and running") + + os.Setenv("TINKERBELL_CERT_URL", "http://127.0.0.1:42114/cert") + os.Setenv("TINKERBELL_GRPC_AUTHORITY", "127.0.0.1:42113") + client.Setup() + _, err = client.HardwareClient.All(ctx, &hardware.Empty{}) + if err != nil { + t.Fatal(err) + } + hwDataFile := "data.json" + + err = registerHardwares(ctx, hwDataFile) + if err != nil { + t.Fatal(err) + } + + templateID, err := registerTemplates(ctx, "hello-world.tmpl") + if err != nil { + t.Fatal(err) + } + + t.Logf("templateID: %s", templateID) + + firstWorkflowID, err := createWorkflow(ctx, templateID) + if err != nil { + t.Fatal(err) + } + + t.Logf("First WorkflowID: %s", firstWorkflowID) + + templateID, err = registerTemplates(ctx, "hello-world-again.tmpl") + if err != nil { + t.Fatal(err) + } + + t.Logf("templateID: %s", templateID) + + secondWorkflowID, err := createWorkflow(ctx, templateID) + if err != nil { + t.Fatal(err) + } + + t.Logf("Second WorkflowID: %s", secondWorkflowID) + + os.Setenv("VAGRANT_WORKER_GUI", "false") + worker, err := vagrant.Up(ctx, + vagrant.WithLogger(t.Logf), + vagrant.WithMachineName("worker"), + vagrant.WithWorkdir("../../deploy/vagrant"), + vagrant.RunAsync(), + ) + if err != nil { + t.Fatal(err) + } + + defer func() { + err := worker.Destroy(ctx) + if err != nil { + t.Error(err) + } + }() + + for iii := 0; iii < 30; iii++ { + events, err := client.WorkflowClient.ShowWorkflowEvents(ctx, &workflow.GetRequest{ + Id: firstWorkflowID, + }) + if err != nil { + t.Fatal(err) + } + for event, err := events.Recv(); err == nil && event != nil; event, err = events.Recv() { + if event.ActionName == "hello_world" && event.ActionStatus == workflow.ActionState_ACTION_SUCCESS { + t.Logf("action %s SUCCESSFULL as expected", event.ActionName) + } + } + + events, err = client.WorkflowClient.ShowWorkflowEvents(ctx, &workflow.GetRequest{ + Id: secondWorkflowID, + }) + if err != nil { + t.Fatal(err) + } + for event, err := events.Recv(); err == nil && event != nil; event, err = events.Recv() { + if event.ActionName == "hello_world_again" && event.ActionStatus == workflow.ActionState_ACTION_SUCCESS { + t.Logf("action %s SUCCESSFULL as expected", event.ActionName) + return + } + } + time.Sleep(5 * time.Second) + } + t.Fatal("Workflow never got to a complite state or it didn't make it on time (5m)") +} + func createWorkflow(ctx context.Context, templateID string) (string, error) { res, err := client.WorkflowClient.CreateWorkflow(ctx, &workflow.CreateRequest{ Template: templateID,