Skip to content

Commit

Permalink
Merge pull request #75 from arangodb/bug-fix/check-result-of-version-up
Browse files Browse the repository at this point in the history
check result of api version call
  • Loading branch information
ObiWahn authored Mar 26, 2018
2 parents 284b2e2 + 24ee46d commit e7bf5e7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
20 changes: 18 additions & 2 deletions tests/deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,30 @@ 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 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)
}
waitUntilVersionUp(dbclient)

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)
Expand Down
17 changes: 15 additions & 2 deletions tests/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit e7bf5e7

Please sign in to comment.