1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.arvados.org/arvados.git/lib/ctrlctx"
13 "git.arvados.org/arvados.git/sdk/go/arvados"
14 "git.arvados.org/arvados.git/sdk/go/arvadostest"
15 "git.arvados.org/arvados.git/sdk/go/auth"
16 "git.arvados.org/arvados.git/sdk/go/ctxlog"
17 "git.arvados.org/arvados.git/sdk/go/httpserver"
18 check "gopkg.in/check.v1"
21 var _ = check.Suite(&collectionSuite{})
23 type collectionSuite struct {
27 func (s *collectionSuite) TestMultipleBackendFailureStatus(c *check.C) {
28 nxPDH := "a4f995dd0c08216f37cb1bdec990f0cd+1234"
29 s.cluster.ClusterID = "local"
30 for _, trial := range []struct {
34 remoteStatus map[string]int
38 "all backends return 404 => 404",
39 arvadostest.SystemRootToken,
42 "aaaaa": http.StatusNotFound,
43 "bbbbb": http.StatusNotFound,
48 "all backends return 401 => 401 (e.g., bad token)",
49 arvadostest.SystemRootToken,
50 http.StatusUnauthorized,
52 "aaaaa": http.StatusUnauthorized,
53 "bbbbb": http.StatusUnauthorized,
55 http.StatusUnauthorized,
58 "local 404, remotes 403 => 422 (mix of non-retryable errors)",
59 arvadostest.SystemRootToken,
62 "aaaaa": http.StatusForbidden,
63 "bbbbb": http.StatusForbidden,
65 http.StatusUnprocessableEntity,
68 "local 404, remotes 401/403/404 => 422 (mix of non-retryable errors)",
69 arvadostest.SystemRootToken,
72 "aaaaa": http.StatusUnauthorized,
73 "bbbbb": http.StatusForbidden,
74 "ccccc": http.StatusNotFound,
76 http.StatusUnprocessableEntity,
79 "local 404, remotes 401/403/500 => 502 (at least one remote is retryable)",
80 arvadostest.SystemRootToken,
83 "aaaaa": http.StatusUnauthorized,
84 "bbbbb": http.StatusForbidden,
85 "ccccc": http.StatusInternalServerError,
87 http.StatusBadGateway,
90 c.Logf("trial: %v", trial)
91 s.fed = New(s.ctx, s.cluster, nil, (&ctrlctx.DBConnector{PostgreSQL: s.cluster.PostgreSQL}).GetDB)
92 s.fed.local = &arvadostest.APIStub{Error: httpserver.ErrorWithStatus(fmt.Errorf("stub error %d", trial.localStatus), trial.localStatus)}
93 for id, status := range trial.remoteStatus {
94 s.addDirectRemote(c, id, &arvadostest.APIStub{Error: httpserver.ErrorWithStatus(fmt.Errorf("stub error %d", status), status)})
97 ctx := context.Background()
98 ctx = ctxlog.Context(ctx, ctxlog.TestLogger(c))
99 if trial.token != "" {
100 ctx = auth.NewContext(ctx, &auth.Credentials{Tokens: []string{trial.token}})
103 _, err := s.fed.CollectionGet(s.ctx, arvados.GetOptions{UUID: nxPDH})
104 c.Check(err.(httpserver.HTTPStatusError).HTTPStatus(), check.Equals, trial.expectStatus)