X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/322599005b9425223195f8b903f0aa2cfc4b7db9..bc25d5adc43cf10b6df7dc28556aba083f34444a:/sdk/go/arvadosclient/arvadosclient_test.go diff --git a/sdk/go/arvadosclient/arvadosclient_test.go b/sdk/go/arvadosclient/arvadosclient_test.go index ecd9e2c6e0..b074e21e81 100644 --- a/sdk/go/arvadosclient/arvadosclient_test.go +++ b/sdk/go/arvadosclient/arvadosclient_test.go @@ -10,8 +10,10 @@ import ( "net/http" "os" "testing" + "time" - "git.curoverse.com/arvados.git/sdk/go/arvadostest" + "git.arvados.org/arvados.git/sdk/go/arvados" + "git.arvados.org/arvados.git/sdk/go/arvadostest" . "gopkg.in/check.v1" ) @@ -28,14 +30,12 @@ var _ = Suite(&MockArvadosServerSuite{}) type ServerRequiredSuite struct{} func (s *ServerRequiredSuite) SetUpSuite(c *C) { - arvadostest.StartAPI() arvadostest.StartKeep(2, false) - RetryDelay = 0 + RetryDelay = 2 * time.Second } func (s *ServerRequiredSuite) TearDownSuite(c *C) { arvadostest.StopKeep(2) - arvadostest.StopAPI() } func (s *ServerRequiredSuite) SetUpTest(c *C) { @@ -63,6 +63,7 @@ func (s *ServerRequiredSuite) TestMakeArvadosClientInsecure(c *C) { func (s *ServerRequiredSuite) TestGetInvalidUUID(c *C) { arv, err := MakeArvadosClient() + c.Assert(err, IsNil) getback := make(Dict) err = arv.Get("collections", "", nil, &getback) @@ -80,6 +81,7 @@ func (s *ServerRequiredSuite) TestGetInvalidUUID(c *C) { func (s *ServerRequiredSuite) TestGetValidUUID(c *C) { arv, err := MakeArvadosClient() + c.Assert(err, IsNil) getback := make(Dict) err = arv.Get("collections", "zzzzz-4zz18-abcdeabcdeabcde", nil, &getback) @@ -95,6 +97,7 @@ func (s *ServerRequiredSuite) TestGetValidUUID(c *C) { func (s *ServerRequiredSuite) TestInvalidResourceType(c *C) { arv, err := MakeArvadosClient() + c.Assert(err, IsNil) getback := make(Dict) err = arv.Get("unicorns", "zzzzz-zebra-unicorn7unicorn", nil, &getback) @@ -141,6 +144,7 @@ func (s *ServerRequiredSuite) TestErrorResponse(c *C) { func (s *ServerRequiredSuite) TestAPIDiscovery_Get_defaultCollectionReplication(c *C) { arv, err := MakeArvadosClient() + c.Assert(err, IsNil) value, err := arv.Discovery("defaultCollectionReplication") c.Assert(err, IsNil) c.Assert(value, NotNil) @@ -148,11 +152,68 @@ func (s *ServerRequiredSuite) TestAPIDiscovery_Get_defaultCollectionReplication( func (s *ServerRequiredSuite) TestAPIDiscovery_Get_noSuchParameter(c *C) { arv, err := MakeArvadosClient() + c.Assert(err, IsNil) value, err := arv.Discovery("noSuchParameter") c.Assert(err, NotNil) c.Assert(value, IsNil) } +func (s *ServerRequiredSuite) TestAPIClusterConfig_Get_StorageClasses(c *C) { + arv, err := MakeArvadosClient() + c.Assert(err, IsNil) + data, err := arv.ClusterConfig("StorageClasses") + c.Assert(err, IsNil) + c.Assert(data, NotNil) + clusterConfig := data.(map[string]interface{}) + _, ok := clusterConfig["default"] + c.Assert(ok, Equals, true) +} + +func (s *ServerRequiredSuite) TestAPIClusterConfig_Get_All(c *C) { + arv, err := MakeArvadosClient() + c.Assert(err, IsNil) + data, err := arv.ClusterConfig("") + c.Assert(err, IsNil) + c.Assert(data, NotNil) + clusterConfig := data.(map[string]interface{}) + _, ok := clusterConfig["StorageClasses"] + c.Assert(ok, Equals, true) +} + +func (s *ServerRequiredSuite) TestAPIClusterConfig_Get_noSuchSection(c *C) { + arv, err := MakeArvadosClient() + c.Assert(err, IsNil) + data, err := arv.ClusterConfig("noSuchSection") + c.Assert(err, NotNil) + c.Assert(data, IsNil) +} + +func (s *ServerRequiredSuite) TestCreateLarge(c *C) { + arv, err := MakeArvadosClient() + c.Assert(err, IsNil) + + txt := arvados.SignLocator("d41d8cd98f00b204e9800998ecf8427e+0", arv.ApiToken, time.Now().Add(time.Minute), time.Minute, []byte(arvadostest.SystemRootToken)) + // Ensure our request body is bigger than the Go http server's + // default max size, 10 MB. + for len(txt) < 12000000 { + txt = txt + " " + txt + } + txt = ". " + txt + " 0:0:foo\n" + + resp := Dict{} + err = arv.Create("collections", Dict{ + "ensure_unique_name": true, + "collection": Dict{ + "is_trashed": true, + "name": "test", + "manifest_text": txt, + }, + }, &resp) + c.Check(err, IsNil) + c.Check(resp["portable_data_hash"], Not(Equals), "") + c.Check(resp["portable_data_hash"], Not(Equals), "d41d8cd98f00b204e9800998ecf8427e+0") +} + type UnitSuite struct{} func (s *UnitSuite) TestUUIDMatch(c *C) { @@ -187,7 +248,7 @@ func (s *UnitSuite) TestPDHMatch(c *C) { type MockArvadosServerSuite struct{} func (s *MockArvadosServerSuite) SetUpSuite(c *C) { - RetryDelay = 0 + RetryDelay = 100 * time.Millisecond } func (s *MockArvadosServerSuite) SetUpTest(c *C) { @@ -218,15 +279,17 @@ type APIStub struct { } func (h *APIStub) ServeHTTP(resp http.ResponseWriter, req *http.Request) { - if req.URL.Path == "/redirect-loop" { - http.Redirect(resp, req, "/redirect-loop", http.StatusFound) - return - } - if h.respStatus[h.retryAttempts] < 0 { - // Fail the client's Do() by starting a redirect loop - http.Redirect(resp, req, "/redirect-loop", http.StatusFound) + if status := h.respStatus[h.retryAttempts]; status < 0 { + // Fail the client's Do() by hanging up without + // sending an HTTP response header. + conn, _, err := resp.(http.Hijacker).Hijack() + if err != nil { + panic(err) + } + conn.Write([]byte("zzzzzzzzzz")) + conn.Close() } else { - resp.WriteHeader(h.respStatus[h.retryAttempts]) + resp.WriteHeader(status) resp.Write([]byte(h.responseBody[h.retryAttempts])) } h.retryAttempts++ @@ -241,22 +304,22 @@ func (s *MockArvadosServerSuite) TestWithRetries(c *C) { "create", 0, 200, []int{200, 500}, []string{`{"ok":"ok"}`, ``}, }, { - "get", 0, 500, []int{500, 500, 500, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, + "get", 0, 423, []int{500, 500, 423, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, }, { - "create", 0, 500, []int{500, 500, 500, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, + "create", 0, 423, []int{500, 500, 423, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, }, { - "update", 0, 500, []int{500, 500, 500, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, + "update", 0, 422, []int{500, 500, 422, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, }, { - "delete", 0, 500, []int{500, 500, 500, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, + "delete", 0, 422, []int{500, 500, 422, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, }, { - "get", 0, 502, []int{500, 500, 502, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, + "get", 0, 401, []int{500, 502, 401, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, }, { - "create", 0, 502, []int{500, 500, 502, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, + "create", 0, 422, []int{500, 502, 422, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, }, { "get", 0, 200, []int{500, 500, 200}, []string{``, ``, `{"ok":"ok"}`}, @@ -276,6 +339,12 @@ func (s *MockArvadosServerSuite) TestWithRetries(c *C) { { "create", 0, 401, []int{401, 200}, []string{``, `{"ok":"ok"}`}, }, + { + "create", 0, 403, []int{403, 200}, []string{``, `{"ok":"ok"}`}, + }, + { + "create", 0, 422, []int{422, 200}, []string{``, `{"ok":"ok"}`}, + }, { "get", 0, 404, []int{404, 200}, []string{``, `{"ok":"ok"}`}, }, @@ -291,11 +360,13 @@ func (s *MockArvadosServerSuite) TestWithRetries(c *C) { { "get", 0, 200, []int{-1, -1, 200}, []string{``, ``, `{"ok":"ok"}`}, }, - // "POST" is not safe to retry: fail after one error + // "POST" protocol error is safe to retry { - "create", 0, -1, []int{-1, 200}, []string{``, `{"ok":"ok"}`}, + "create", 0, 200, []int{-1, 200}, []string{``, `{"ok":"ok"}`}, }, } { + c.Logf("stub: %#v", stub) + api, err := RunFakeArvadosServer(&stub) c.Check(err, IsNil) @@ -335,7 +406,9 @@ func (s *MockArvadosServerSuite) TestWithRetries(c *C) { default: c.Check(err, NotNil) c.Check(err, ErrorMatches, fmt.Sprintf("arvados API server error: %d.*", stub.expected)) - c.Check(err.(APIServerError).HttpStatusCode, Equals, stub.expected) + if c.Check(err, FitsTypeOf, APIServerError{}) { + c.Check(err.(APIServerError).HttpStatusCode, Equals, stub.expected) + } } } }