From 3ded4c192b1fc655d9fffa225f792055f10f78c9 Mon Sep 17 00:00:00 2001 From: radhika Date: Sat, 7 Nov 2015 09:00:49 -0500 Subject: [PATCH] 5538: correct retryable list and use it to determine whether to close idle connections; add a few more test cases. --- sdk/go/arvadosclient/arvadosclient.go | 8 ++++---- sdk/go/arvadosclient/arvadosclient_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/sdk/go/arvadosclient/arvadosclient.go b/sdk/go/arvadosclient/arvadosclient.go index 2b6a36abec..b67eaa59a6 100644 --- a/sdk/go/arvadosclient/arvadosclient.go +++ b/sdk/go/arvadosclient/arvadosclient.go @@ -165,13 +165,13 @@ func (c ArvadosClient) CallRaw(method string, resourceType string, uuid string, retryable := false switch method { - case "GET", "HEAD", "PUT", "OPTIONS", "POST", "DELETE": + case "GET", "HEAD", "PUT", "OPTIONS", "DELETE": retryable = true } - // POST and DELETE are not safe to retry automatically, so we minimize - // such failures by always using a new or recently active socket - if method == "POST" || method == "DELETE" { + // Non-retryable methods such as POST are not safe to retry automatically, + // so we minimize such failures by always using a new or recently active socket + if !retryable { if time.Since(c.lastClosedIdlesAt) > MaxIdleConnectionDuration { c.lastClosedIdlesAt = time.Now() c.Client.Transport.(*http.Transport).CloseIdleConnections() diff --git a/sdk/go/arvadosclient/arvadosclient_test.go b/sdk/go/arvadosclient/arvadosclient_test.go index a4fe136af5..bc88c44022 100644 --- a/sdk/go/arvadosclient/arvadosclient_test.go +++ b/sdk/go/arvadosclient/arvadosclient_test.go @@ -272,6 +272,12 @@ type APIStub struct { func (s *MockArvadosServerSuite) TestWithRetries(c *C) { for _, stub := range []APIStub{ + { + "get", 0, 200, []int{200, 500}, []string{`{"ok":"ok"}`, ``}, + }, + { + "create", 0, 200, []int{200, 500}, []string{`{"ok":"ok"}`, ``}, + }, { "get", 0, 500, []int{500, 500, 500, 200}, []string{``, ``, ``, `{"ok":"ok"}`}, }, @@ -296,6 +302,12 @@ func (s *MockArvadosServerSuite) TestWithRetries(c *C) { { "create", 0, 200, []int{500, 500, 200}, []string{``, ``, `{"ok":"ok"}`}, }, + { + "delete", 0, 200, []int{500, 500, 200}, []string{``, ``, `{"ok":"ok"}`}, + }, + { + "update", 0, 200, []int{500, 500, 200}, []string{``, ``, `{"ok":"ok"}`}, + }, { "get", 0, 401, []int{401, 200}, []string{``, `{"ok":"ok"}`}, }, -- 2.30.2