From 97d38f998ed80e157edff2e9b022a2b607a96737 Mon Sep 17 00:00:00 2001 From: ajanikow <12255597+ajanikow@users.noreply.github.com> Date: Mon, 31 May 2021 06:39:14 +0000 Subject: [PATCH 1/2] Retry on 503 in tests --- error.go | 10 +++++++ test/agency_test.go | 18 ++++++++++++ test/check_test.go | 69 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 test/check_test.go diff --git a/error.go b/error.go index 59fbf3b2..ab72c23e 100644 --- a/error.go +++ b/error.go @@ -100,6 +100,16 @@ func IsArangoError(err error) bool { return ok && ae.HasError } +// AsArangoError returns true when the given error is an ArangoError together with an object. +func AsArangoError(err error) (ArangoError, bool) { + ae, ok := Cause(err).(ArangoError) + if ok { + return ae, true + } else { + return ArangoError{}, false + } +} + // IsArangoErrorWithCode returns true when the given error is an ArangoError and its Code field is equal to the given code. func IsArangoErrorWithCode(err error, code int) bool { ae, ok := Cause(err).(ArangoError) diff --git a/test/agency_test.go b/test/agency_test.go index 384eba69..09c23c1f 100644 --- a/test/agency_test.go +++ b/test/agency_test.go @@ -42,6 +42,19 @@ import ( "github.com/stretchr/testify/require" ) +func checkAgencyEndpoints(ctx context.Context, c driver.Client) error { + cl, err := c.Cluster(ctx) + if err != nil { + return err + } + _, err = cl.Health(ctx) + if err != nil { + return err + } + + return nil +} + // getAgencyEndpoints queries the cluster to get all agency endpoints. func getAgencyEndpoints(ctx context.Context, c driver.Client) ([]string, error) { cl, err := c.Cluster(ctx) @@ -114,6 +127,11 @@ func getAgencyConnection(ctx context.Context, t testEnv, c driver.Client) (agenc // These tests assume an HTTP connetion, so we skip under this condition return nil, driver.ArangoError{HasError: true, Code: 412, ErrorMessage: "Using vst is not supported in agency tests"} } + + if err := driverErrorCheck(ctx, c, checkAgencyEndpoints, driverErrorCheckRetry503).Retry(125*time.Millisecond, time.Minute); err != nil { + return nil, err + } + endpoints, err := getAgencyEndpoints(ctx, c) if err != nil { return nil, err diff --git a/test/check_test.go b/test/check_test.go new file mode 100644 index 00000000..2fdb7f28 --- /dev/null +++ b/test/check_test.go @@ -0,0 +1,69 @@ +// +// DISCLAIMER +// +// Copyright 2021 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// +// Author Adam Janikowski +// + +package test + +import ( + "context" + "net/http" + + "github.com/arangodb/go-driver" +) + +type driverErrorCheckFunc func(err error) (bool, error) +type driverErrorChecker func(ctx context.Context, client driver.Client) error + +func driverErrorCheck(ctx context.Context, c driver.Client, checker driverErrorChecker, checks ...driverErrorCheckFunc) retryFunc { + return func() error { + err := checker(ctx, c) + + for _, check := range checks { + if valid, err := check(err); err != nil { + return err + } else if !valid { + return nil + } + } + + return interrupt{} + } +} + +func driverErrorCheckRetry503(err error) (bool, error) { + if err == nil { + return true, nil + } + + if ae, ok := driver.AsArangoError(err); !ok { + return false, err + } else { + if !ae.HasError { + return true, nil + } + switch ae.Code { + case http.StatusServiceUnavailable: + return false, nil + default: + return true, err + } + } +} From 5721810463cf1fc0245db079501479e4364d5722 Mon Sep 17 00:00:00 2001 From: ajanikow <12255597+ajanikow@users.noreply.github.com> Date: Mon, 31 May 2021 07:26:45 +0000 Subject: [PATCH 2/2] Add Go image in travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b12f5b0a..9d9b6037 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,7 @@ services: language: go env: - - TEST_SUITE=run-unit-tests ALWAYS=1 + - TEST_SUITE=run-unit-tests GOIMAGE=gcr.io/gcr-for-testing/golang:1.13.4-stretch ALWAYS=1 - TEST_SUITE=run-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.13.4-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb:3.6 - TEST_SUITE=run-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.13.4-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb/arangodb:latest ALWAYS=1 - TEST_SUITE=run-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.13.4-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb:3.7