From 83f970793e795e393c79c478f82931a3a16fb6f7 Mon Sep 17 00:00:00 2001 From: Jan Christoph Uhde Date: Mon, 26 Mar 2018 09:29:40 +0200 Subject: [PATCH 1/2] check result of api version call --- tests/deployments_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/deployments_test.go b/tests/deployments_test.go index ae88a1fe2..23fd653fa 100644 --- a/tests/deployments_test.go +++ b/tests/deployments_test.go @@ -127,14 +127,18 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage if err != nil { t.Fatal("Unable to create connection to: %v", agent.ID) } - waitUntilVersionUp(dbclient) + if waitUntilVersionUp(dbclient) != nil { + t.Fatal("Version check failed for: %v", single.ID) + } } for _, single := range singles { dbclient, err := arangod.CreateArangodClient(ctx, k8sClient.CoreV1(), deployment, api.ServerGroupAgents, single.ID) if err != nil { t.Fatal("Unable to create connection to: %v", single.ID) } - waitUntilVersionUp(dbclient) + if waitUntilVersionUp(dbclient) != nil { + t.Fatal("Version check failed for: %v", single.ID) + } } default: t.Fatalf("DeploymentMode %v is not supported!", mode) From 24ee46d82c0cb591537b84735fd9969a678bcbbe Mon Sep 17 00:00:00 2001 From: Jan Christoph Uhde Date: Mon, 26 Mar 2018 09:56:04 +0200 Subject: [PATCH 2/2] add allowNoLeaderResponse paramerter to waitUntilVersionUp --- tests/deployments_test.go | 18 +++++++++++++++--- tests/test_util.go | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/tests/deployments_test.go b/tests/deployments_test.go index 23fd653fa..17a467fd7 100644 --- a/tests/deployments_test.go +++ b/tests/deployments_test.go @@ -127,19 +127,31 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage if err != nil { t.Fatal("Unable to create connection to: %v", agent.ID) } - if waitUntilVersionUp(dbclient) != nil { - t.Fatal("Version check failed for: %v", single.ID) + + if err := waitUntilVersionUp(dbclient); err != nil { + t.Fatal("Version check failed for: %v", agent.ID) } } + + var goodResults, noLeaderResults int for _, single := range singles { dbclient, err := arangod.CreateArangodClient(ctx, k8sClient.CoreV1(), deployment, api.ServerGroupAgents, single.ID) if err != nil { t.Fatal("Unable to create connection to: %v", single.ID) } - if waitUntilVersionUp(dbclient) != nil { + + if err := waitUntilVersionUp(dbclient, true); err == nil { + goodResults++ + } else if driver.IsNoLeader(err) { + noLeaderResults++ + } else { t.Fatal("Version check failed for: %v", single.ID) } } + + if goodResults < 1 || noLeaderResults > 1 { + t.Fatal("Wrong number of results: good %v - noleader %v", goodResults, noLeaderResults) + } default: t.Fatalf("DeploymentMode %v is not supported!", mode) } diff --git a/tests/test_util.go b/tests/test_util.go index eaac48f02..fa187a3c5 100644 --- a/tests/test_util.go +++ b/tests/test_util.go @@ -207,17 +207,30 @@ func waitUntilClusterHealth(cli driver.Client, predicate func(driver.ClusterHeal // waitUntilVersionUp waits until the arango database responds to // an `/_api/version` request without an error. -func waitUntilVersionUp(cli driver.Client) error { +func waitUntilVersionUp(cli driver.Client, allowNoLeaderResponse ...bool) error { + var noLeaderErr error + allowNoLead := len(allowNoLeaderResponse) > 0 && allowNoLeaderResponse[0] ctx := context.Background() + op := func() error { - if _, err := cli.Version(ctx); err != nil { + if _, err := cli.Version(ctx); allowNoLead && driver.IsNoLeader(err) { + noLeaderErr = err + return nil //return nil to make the retry below pass + } else if err != nil { return maskAny(err) } return nil } + if err := retry.Retry(op, deploymentReadyTimeout); err != nil { return maskAny(err) } + + // noLeadErr updated in op + if noLeaderErr != nil { + return maskAny(noLeaderErr) + } + return nil }