[ARVADOS] created: 57fa190ee2782d88402b0638010e51b1c2b97d2c
Git user
git at public.curoverse.com
Fri May 19 19:21:27 EDT 2017
at 57fa190ee2782d88402b0638010e51b1c2b97d2c (commit)
commit 57fa190ee2782d88402b0638010e51b1c2b97d2c
Author: Tom Clegg <tom at curoverse.com>
Date: Fri May 19 16:35:46 2017 -0400
9005: Add connection leak test.
diff --git a/services/keep-web/server_test.go b/services/keep-web/server_test.go
index a5d8189..e23e7d9 100644
--- a/services/keep-web/server_test.go
+++ b/services/keep-web/server_test.go
@@ -1,11 +1,13 @@
package main
import (
+ "bytes"
"crypto/md5"
"fmt"
"io"
"io/ioutil"
"net"
+ "net/http"
"os"
"os/exec"
"strings"
@@ -27,6 +29,43 @@ type ServerSuite struct {
testServer *server
}
+// Make several requests that trigger collectionreader's prefetch
+// mechanism, disable block caching between requests, and check for
+// leaked HTTP connections to keepstore servers.
+func (s *ServerSuite) TestConnectionLeak(c *check.C) {
+ _, uuid, token := makeCollection(c, 2, 1<<21, true)
+ u := mustParseURL("http://" + s.testServer.Addr + "/testdata.bin")
+ hdr := http.Header{
+ "Authorization": {"OAuth2 " + token},
+ "Range": {"bytes=2000000-2020000"},
+ }
+
+ var client http.Client
+ for i := 0; i < 50; i++ {
+ keepclient.DefaultBlockCache = &keepclient.BlockCache{}
+ resp, err := client.Do(&http.Request{
+ Method: "GET",
+ Host: uuid + ".example.com",
+ URL: u,
+ Header: hdr,
+ })
+ c.Assert(err, check.IsNil)
+ c.Check(resp.StatusCode, check.Equals, http.StatusPartialContent)
+ buf, err := ioutil.ReadAll(resp.Body)
+ c.Check(err, check.IsNil)
+ c.Check(len(buf), check.Equals, 20001)
+ resp.Body.Close()
+ }
+
+ netstatCmd := fmt.Sprintf("netstat -pane | grep ' %d/' | grep -v %q | grep -w ESTABLISHED", os.Getpid(), " "+s.testServer.Addr+" ")
+ buf, err := exec.Command("bash", "-e", "-o", "pipefail", "-c", netstatCmd).CombinedOutput()
+ c.Logf("$ %s\n%s", netstatCmd, buf)
+ c.Check(err, check.IsNil)
+ conns := bytes.Count(buf, []byte{'\n'})
+ c.Logf("... ~%d connections with my pid", conns)
+ c.Check(conns < 20, check.Equals, true)
+}
+
func (s *ServerSuite) TestNoToken(c *check.C) {
for _, token := range []string{
"",
@@ -98,23 +137,27 @@ func (s *ServerSuite) Test100BlockFile(c *check.C) {
}
}
-func make100BlockCollection(c *check.C, blocksize int) (data []byte, uuid string, token string) {
+func makeCollection(c *check.C, nblocks, blocksize int, vary bool) (data []byte, uuid string, token string) {
testdata := make([]byte, blocksize)
- for i := 0; i < blocksize; i++ {
- testdata[i] = byte(' ')
- }
arv, err := arvadosclient.MakeArvadosClient()
c.Assert(err, check.Equals, nil)
arv.ApiToken = arvadostest.ActiveToken
kc, err := keepclient.MakeKeepClient(arv)
c.Assert(err, check.Equals, nil)
- loc, _, err := kc.PutB(testdata[:])
- c.Assert(err, check.Equals, nil)
+
mtext := "."
- for i := 0; i < 100; i++ {
+ var loc string
+ for i := 0; i < nblocks; i++ {
+ if vary || i == 0 {
+ for b := 0; b < blocksize; b++ {
+ testdata[b] = byte(i + 1)
+ }
+ loc, _, err = kc.PutB(testdata[:])
+ c.Assert(err, check.Equals, nil)
+ }
mtext = mtext + " " + loc
}
- mtext = mtext + fmt.Sprintf(" 0:%d00:testdata.bin\n", blocksize)
+ mtext = mtext + fmt.Sprintf(" 0:%d:testdata.bin\n", nblocks*blocksize)
coll := map[string]interface{}{}
err = arv.Create("collections",
map[string]interface{}{
@@ -128,7 +171,7 @@ func make100BlockCollection(c *check.C, blocksize int) (data []byte, uuid string
}
func (s *ServerSuite) test100BlockFile(c *check.C, blocksize int) {
- testdata, uuid, token := make100BlockCollection(c, blocksize)
+ testdata, uuid, token := makeCollection(c, 100, blocksize, false)
hdr, body, size := s.runCurl(c, token, uuid+".collections.example.com", "/testdata.bin")
c.Check(hdr, check.Matches, `(?s)HTTP/1.1 200 OK\r\n.*`)
c.Check(hdr, check.Matches, `(?si).*Content-length: `+fmt.Sprintf("%d00", blocksize)+`\r\n.*`)
commit 25fb9f537a70277dc9c7a476a9ebf38a99b3cccf
Author: Tom Clegg <tom at curoverse.com>
Date: Fri May 19 15:05:02 2017 -0400
9005: Skip starting unused http server in handler tests.
diff --git a/services/keep-web/handler_test.go b/services/keep-web/handler_test.go
index 57ac219..f820be1 100644
--- a/services/keep-web/handler_test.go
+++ b/services/keep-web/handler_test.go
@@ -6,20 +6,35 @@ import (
"net/http"
"net/http/httptest"
"net/url"
+ "os"
"regexp"
"strings"
+ "git.curoverse.com/arvados.git/sdk/go/arvados"
"git.curoverse.com/arvados.git/sdk/go/arvadostest"
"git.curoverse.com/arvados.git/sdk/go/auth"
check "gopkg.in/check.v1"
)
-var _ = check.Suite(&UnitSuite{})
+var _ = check.Suite(&HandlerSuite{})
-type UnitSuite struct{}
+type HandlerSuite struct {
+ IntegrationSuite
+ handler *handler
+}
+
+func (s *HandlerSuite) SetUpTest(c *check.C) {
+ arvadostest.ResetEnv()
+ s.handler = &handler{Config: &Config{
+ Client: arvados.Client{
+ APIHost: os.Getenv("ARVADOS_API_HOST"),
+ Insecure: true,
+ },
+ Listen: "127.0.0.1:0",
+ }}
+}
-func (s *UnitSuite) TestCORSPreflight(c *check.C) {
- h := handler{Config: &Config{}}
+func (s *HandlerSuite) TestCORSPreflight(c *check.C) {
u, _ := url.Parse("http://keep-web.example/c=" + arvadostest.FooCollection + "/foo")
req := &http.Request{
Method: "OPTIONS",
@@ -34,7 +49,7 @@ func (s *UnitSuite) TestCORSPreflight(c *check.C) {
// Check preflight for an allowed request
resp := httptest.NewRecorder()
- h.ServeHTTP(resp, req)
+ s.handler.ServeHTTP(resp, req)
c.Check(resp.Code, check.Equals, http.StatusOK)
c.Check(resp.Body.String(), check.Equals, "")
c.Check(resp.Header().Get("Access-Control-Allow-Origin"), check.Equals, "*")
@@ -44,12 +59,13 @@ func (s *UnitSuite) TestCORSPreflight(c *check.C) {
// Check preflight for a disallowed request
resp = httptest.NewRecorder()
req.Header.Set("Access-Control-Request-Method", "DELETE")
- h.ServeHTTP(resp, req)
+ s.handler.ServeHTTP(resp, req)
c.Check(resp.Body.String(), check.Equals, "")
c.Check(resp.Code, check.Equals, http.StatusMethodNotAllowed)
}
-func (s *UnitSuite) TestInvalidUUID(c *check.C) {
+func (s *HandlerSuite) TestInvalidUUID(c *check.C) {
+ s.handler.Config.AnonymousTokens = []string{arvadostest.AnonymousToken}
bogusID := strings.Replace(arvadostest.FooPdh, "+", "-", 1) + "-"
token := arvadostest.ActiveToken
for _, trial := range []string{
@@ -70,10 +86,7 @@ func (s *UnitSuite) TestInvalidUUID(c *check.C) {
RequestURI: u.RequestURI(),
}
resp := httptest.NewRecorder()
- h := handler{Config: &Config{
- AnonymousTokens: []string{arvadostest.AnonymousToken},
- }}
- h.ServeHTTP(resp, req)
+ s.handler.ServeHTTP(resp, req)
c.Check(resp.Code, check.Equals, http.StatusNotFound)
}
}
@@ -86,7 +99,7 @@ func mustParseURL(s string) *url.URL {
return r
}
-func (s *IntegrationSuite) TestVhost404(c *check.C) {
+func (s *HandlerSuite) TestVhost404(c *check.C) {
for _, testURL := range []string{
arvadostest.NonexistentCollection + ".example.com/theperthcountyconspiracy",
arvadostest.NonexistentCollection + ".example.com/t=" + arvadostest.ActiveToken + "/theperthcountyconspiracy",
@@ -98,7 +111,7 @@ func (s *IntegrationSuite) TestVhost404(c *check.C) {
URL: u,
RequestURI: u.RequestURI(),
}
- s.testServer.Handler.ServeHTTP(resp, req)
+ s.handler.ServeHTTP(resp, req)
c.Check(resp.Code, check.Equals, http.StatusNotFound)
c.Check(resp.Body.String(), check.Equals, "")
}
@@ -110,7 +123,7 @@ func (s *IntegrationSuite) TestVhost404(c *check.C) {
// the token is invalid.
type authorizer func(*http.Request, string) int
-func (s *IntegrationSuite) TestVhostViaAuthzHeader(c *check.C) {
+func (s *HandlerSuite) TestVhostViaAuthzHeader(c *check.C) {
s.doVhostRequests(c, authzViaAuthzHeader)
}
func authzViaAuthzHeader(r *http.Request, tok string) int {
@@ -118,7 +131,7 @@ func authzViaAuthzHeader(r *http.Request, tok string) int {
return http.StatusUnauthorized
}
-func (s *IntegrationSuite) TestVhostViaCookieValue(c *check.C) {
+func (s *HandlerSuite) TestVhostViaCookieValue(c *check.C) {
s.doVhostRequests(c, authzViaCookieValue)
}
func authzViaCookieValue(r *http.Request, tok string) int {
@@ -129,7 +142,7 @@ func authzViaCookieValue(r *http.Request, tok string) int {
return http.StatusUnauthorized
}
-func (s *IntegrationSuite) TestVhostViaPath(c *check.C) {
+func (s *HandlerSuite) TestVhostViaPath(c *check.C) {
s.doVhostRequests(c, authzViaPath)
}
func authzViaPath(r *http.Request, tok string) int {
@@ -137,7 +150,7 @@ func authzViaPath(r *http.Request, tok string) int {
return http.StatusNotFound
}
-func (s *IntegrationSuite) TestVhostViaQueryString(c *check.C) {
+func (s *HandlerSuite) TestVhostViaQueryString(c *check.C) {
s.doVhostRequests(c, authzViaQueryString)
}
func authzViaQueryString(r *http.Request, tok string) int {
@@ -145,7 +158,7 @@ func authzViaQueryString(r *http.Request, tok string) int {
return http.StatusUnauthorized
}
-func (s *IntegrationSuite) TestVhostViaPOST(c *check.C) {
+func (s *HandlerSuite) TestVhostViaPOST(c *check.C) {
s.doVhostRequests(c, authzViaPOST)
}
func authzViaPOST(r *http.Request, tok string) int {
@@ -156,7 +169,7 @@ func authzViaPOST(r *http.Request, tok string) int {
return http.StatusUnauthorized
}
-func (s *IntegrationSuite) TestVhostViaXHRPOST(c *check.C) {
+func (s *HandlerSuite) TestVhostViaXHRPOST(c *check.C) {
s.doVhostRequests(c, authzViaPOST)
}
func authzViaXHRPOST(r *http.Request, tok string) int {
@@ -173,7 +186,7 @@ func authzViaXHRPOST(r *http.Request, tok string) int {
// Try some combinations of {url, token} using the given authorization
// mechanism, and verify the result is correct.
-func (s *IntegrationSuite) doVhostRequests(c *check.C, authz authorizer) {
+func (s *HandlerSuite) doVhostRequests(c *check.C, authz authorizer) {
for _, hostPath := range []string{
arvadostest.FooCollection + ".example.com/foo",
arvadostest.FooCollection + "--collections.example.com/foo",
@@ -187,7 +200,7 @@ func (s *IntegrationSuite) doVhostRequests(c *check.C, authz authorizer) {
}
}
-func (s *IntegrationSuite) doVhostRequestsWithHostPath(c *check.C, authz authorizer, hostPath string) {
+func (s *HandlerSuite) doVhostRequestsWithHostPath(c *check.C, authz authorizer, hostPath string) {
for _, tok := range []string{
arvadostest.ActiveToken,
arvadostest.ActiveToken[:15],
@@ -233,9 +246,9 @@ func (s *IntegrationSuite) doVhostRequestsWithHostPath(c *check.C, authz authori
}
}
-func (s *IntegrationSuite) doReq(req *http.Request) (*http.Request, *httptest.ResponseRecorder) {
+func (s *HandlerSuite) doReq(req *http.Request) (*http.Request, *httptest.ResponseRecorder) {
resp := httptest.NewRecorder()
- s.testServer.Handler.ServeHTTP(resp, req)
+ s.handler.ServeHTTP(resp, req)
if resp.Code != http.StatusSeeOther {
return req, resp
}
@@ -254,7 +267,7 @@ func (s *IntegrationSuite) doReq(req *http.Request) (*http.Request, *httptest.Re
return s.doReq(req)
}
-func (s *IntegrationSuite) TestVhostRedirectQueryTokenToCookie(c *check.C) {
+func (s *HandlerSuite) TestVhostRedirectQueryTokenToCookie(c *check.C) {
s.testVhostRedirectTokenToCookie(c, "GET",
arvadostest.FooCollection+".example.com/foo",
"?api_token="+arvadostest.ActiveToken,
@@ -265,7 +278,7 @@ func (s *IntegrationSuite) TestVhostRedirectQueryTokenToCookie(c *check.C) {
)
}
-func (s *IntegrationSuite) TestSingleOriginSecretLink(c *check.C) {
+func (s *HandlerSuite) TestSingleOriginSecretLink(c *check.C) {
s.testVhostRedirectTokenToCookie(c, "GET",
"example.com/c="+arvadostest.FooCollection+"/t="+arvadostest.ActiveToken+"/foo",
"",
@@ -278,7 +291,7 @@ func (s *IntegrationSuite) TestSingleOriginSecretLink(c *check.C) {
// Bad token in URL is 404 Not Found because it doesn't make sense to
// retry the same URL with different authorization.
-func (s *IntegrationSuite) TestSingleOriginSecretLinkBadToken(c *check.C) {
+func (s *HandlerSuite) TestSingleOriginSecretLinkBadToken(c *check.C) {
s.testVhostRedirectTokenToCookie(c, "GET",
"example.com/c="+arvadostest.FooCollection+"/t=bogus/foo",
"",
@@ -292,7 +305,7 @@ func (s *IntegrationSuite) TestSingleOriginSecretLinkBadToken(c *check.C) {
// Bad token in a cookie (even if it got there via our own
// query-string-to-cookie redirect) is, in principle, retryable at the
// same URL so it's 401 Unauthorized.
-func (s *IntegrationSuite) TestVhostRedirectQueryTokenToBogusCookie(c *check.C) {
+func (s *HandlerSuite) TestVhostRedirectQueryTokenToBogusCookie(c *check.C) {
s.testVhostRedirectTokenToCookie(c, "GET",
arvadostest.FooCollection+".example.com/foo",
"?api_token=thisisabogustoken",
@@ -303,7 +316,7 @@ func (s *IntegrationSuite) TestVhostRedirectQueryTokenToBogusCookie(c *check.C)
)
}
-func (s *IntegrationSuite) TestVhostRedirectQueryTokenSingleOriginError(c *check.C) {
+func (s *HandlerSuite) TestVhostRedirectQueryTokenSingleOriginError(c *check.C) {
s.testVhostRedirectTokenToCookie(c, "GET",
"example.com/c="+arvadostest.FooCollection+"/foo",
"?api_token="+arvadostest.ActiveToken,
@@ -317,7 +330,7 @@ func (s *IntegrationSuite) TestVhostRedirectQueryTokenSingleOriginError(c *check
// If client requests an attachment by putting ?disposition=attachment
// in the query string, and gets redirected, the redirect target
// should respond with an attachment.
-func (s *IntegrationSuite) TestVhostRedirectQueryTokenRequestAttachment(c *check.C) {
+func (s *HandlerSuite) TestVhostRedirectQueryTokenRequestAttachment(c *check.C) {
resp := s.testVhostRedirectTokenToCookie(c, "GET",
arvadostest.FooCollection+".example.com/foo",
"?disposition=attachment&api_token="+arvadostest.ActiveToken,
@@ -329,8 +342,8 @@ func (s *IntegrationSuite) TestVhostRedirectQueryTokenRequestAttachment(c *check
c.Check(strings.Split(resp.Header().Get("Content-Disposition"), ";")[0], check.Equals, "attachment")
}
-func (s *IntegrationSuite) TestVhostRedirectQueryTokenTrustAllContent(c *check.C) {
- s.testServer.Config.TrustAllContent = true
+func (s *HandlerSuite) TestVhostRedirectQueryTokenTrustAllContent(c *check.C) {
+ s.handler.Config.TrustAllContent = true
s.testVhostRedirectTokenToCookie(c, "GET",
"example.com/c="+arvadostest.FooCollection+"/foo",
"?api_token="+arvadostest.ActiveToken,
@@ -341,8 +354,8 @@ func (s *IntegrationSuite) TestVhostRedirectQueryTokenTrustAllContent(c *check.C
)
}
-func (s *IntegrationSuite) TestVhostRedirectQueryTokenAttachmentOnlyHost(c *check.C) {
- s.testServer.Config.AttachmentOnlyHost = "example.com:1234"
+func (s *HandlerSuite) TestVhostRedirectQueryTokenAttachmentOnlyHost(c *check.C) {
+ s.handler.Config.AttachmentOnlyHost = "example.com:1234"
s.testVhostRedirectTokenToCookie(c, "GET",
"example.com/c="+arvadostest.FooCollection+"/foo",
@@ -364,7 +377,7 @@ func (s *IntegrationSuite) TestVhostRedirectQueryTokenAttachmentOnlyHost(c *chec
c.Check(resp.Header().Get("Content-Disposition"), check.Equals, "attachment")
}
-func (s *IntegrationSuite) TestVhostRedirectPOSTFormTokenToCookie(c *check.C) {
+func (s *HandlerSuite) TestVhostRedirectPOSTFormTokenToCookie(c *check.C) {
s.testVhostRedirectTokenToCookie(c, "POST",
arvadostest.FooCollection+".example.com/foo",
"",
@@ -375,7 +388,7 @@ func (s *IntegrationSuite) TestVhostRedirectPOSTFormTokenToCookie(c *check.C) {
)
}
-func (s *IntegrationSuite) TestVhostRedirectPOSTFormTokenToCookie404(c *check.C) {
+func (s *HandlerSuite) TestVhostRedirectPOSTFormTokenToCookie404(c *check.C) {
s.testVhostRedirectTokenToCookie(c, "POST",
arvadostest.FooCollection+".example.com/foo",
"",
@@ -386,8 +399,8 @@ func (s *IntegrationSuite) TestVhostRedirectPOSTFormTokenToCookie404(c *check.C)
)
}
-func (s *IntegrationSuite) TestAnonymousTokenOK(c *check.C) {
- s.testServer.Config.AnonymousTokens = []string{arvadostest.AnonymousToken}
+func (s *HandlerSuite) TestAnonymousTokenOK(c *check.C) {
+ s.handler.Config.AnonymousTokens = []string{arvadostest.AnonymousToken}
s.testVhostRedirectTokenToCookie(c, "GET",
"example.com/c="+arvadostest.HelloWorldCollection+"/Hello%20world.txt",
"",
@@ -398,8 +411,8 @@ func (s *IntegrationSuite) TestAnonymousTokenOK(c *check.C) {
)
}
-func (s *IntegrationSuite) TestAnonymousTokenError(c *check.C) {
- s.testServer.Config.AnonymousTokens = []string{"anonymousTokenConfiguredButInvalid"}
+func (s *HandlerSuite) TestAnonymousTokenError(c *check.C) {
+ s.handler.Config.AnonymousTokens = []string{"anonymousTokenConfiguredButInvalid"}
s.testVhostRedirectTokenToCookie(c, "GET",
"example.com/c="+arvadostest.HelloWorldCollection+"/Hello%20world.txt",
"",
@@ -415,7 +428,7 @@ func (s *IntegrationSuite) TestAnonymousTokenError(c *check.C) {
// with content instead of a redirect) and an Origin header that gets
// added automatically by the browser (telling us it's desirable to do
// so).
-func (s *IntegrationSuite) TestXHRNoRedirect(c *check.C) {
+func (s *HandlerSuite) TestXHRNoRedirect(c *check.C) {
u, _ := url.Parse("http://example.com/c=" + arvadostest.FooCollection + "/foo")
req := &http.Request{
Method: "POST",
@@ -432,13 +445,13 @@ func (s *IntegrationSuite) TestXHRNoRedirect(c *check.C) {
}.Encode())),
}
resp := httptest.NewRecorder()
- s.testServer.Handler.ServeHTTP(resp, req)
+ s.handler.ServeHTTP(resp, req)
c.Check(resp.Code, check.Equals, http.StatusOK)
c.Check(resp.Body.String(), check.Equals, "foo")
c.Check(resp.Header().Get("Access-Control-Allow-Origin"), check.Equals, "*")
}
-func (s *IntegrationSuite) testVhostRedirectTokenToCookie(c *check.C, method, hostPath, queryString, contentType, reqBody string, expectStatus int, expectRespBody string) *httptest.ResponseRecorder {
+func (s *HandlerSuite) testVhostRedirectTokenToCookie(c *check.C, method, hostPath, queryString, contentType, reqBody string, expectStatus int, expectRespBody string) *httptest.ResponseRecorder {
u, _ := url.Parse(`http://` + hostPath + queryString)
req := &http.Request{
Method: method,
@@ -455,7 +468,7 @@ func (s *IntegrationSuite) testVhostRedirectTokenToCookie(c *check.C, method, ho
c.Check(resp.Body.String(), check.Equals, expectRespBody)
}()
- s.testServer.Handler.ServeHTTP(resp, req)
+ s.handler.ServeHTTP(resp, req)
if resp.Code != http.StatusSeeOther {
return resp
}
@@ -475,7 +488,7 @@ func (s *IntegrationSuite) testVhostRedirectTokenToCookie(c *check.C, method, ho
}
resp = httptest.NewRecorder()
- s.testServer.Handler.ServeHTTP(resp, req)
+ s.handler.ServeHTTP(resp, req)
c.Check(resp.Header().Get("Location"), check.Equals, "")
return resp
}
diff --git a/services/keep-web/integration_test.go b/services/keep-web/integration_test.go
new file mode 100644
index 0000000..660dad9
--- /dev/null
+++ b/services/keep-web/integration_test.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+ "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
+ "git.curoverse.com/arvados.git/sdk/go/arvadostest"
+ "git.curoverse.com/arvados.git/sdk/go/keepclient"
+ check "gopkg.in/check.v1"
+)
+
+var _ = check.Suite(&IntegrationSuite{})
+
+// IntegrationSuite tests need an API server and a keep-web server
+type IntegrationSuite struct{}
+
+func (s *IntegrationSuite) SetUpSuite(c *check.C) {
+ arvadostest.StartAPI()
+ arvadostest.StartKeep(2, true)
+
+ arv, err := arvadosclient.MakeArvadosClient()
+ c.Assert(err, check.Equals, nil)
+ arv.ApiToken = arvadostest.ActiveToken
+ kc, err := keepclient.MakeKeepClient(arv)
+ c.Assert(err, check.Equals, nil)
+ kc.PutB([]byte("Hello world\n"))
+ kc.PutB([]byte("foo"))
+ kc.PutB([]byte("foobar"))
+}
+
+func (s *IntegrationSuite) TearDownSuite(c *check.C) {
+ arvadostest.StopKeep(2)
+ arvadostest.StopAPI()
+}
diff --git a/services/keep-web/ranges_test.go b/services/keep-web/ranges_test.go
index 186306d..32e8ae2 100644
--- a/services/keep-web/ranges_test.go
+++ b/services/keep-web/ranges_test.go
@@ -11,7 +11,7 @@ import (
check "gopkg.in/check.v1"
)
-func (s *IntegrationSuite) TestRanges(c *check.C) {
+func (s *ServerSuite) TestRanges(c *check.C) {
blocksize := 1000000
var uuid string
{
diff --git a/services/keep-web/server_test.go b/services/keep-web/server_test.go
index 6441364..a5d8189 100644
--- a/services/keep-web/server_test.go
+++ b/services/keep-web/server_test.go
@@ -20,14 +20,14 @@ import (
var testAPIHost = os.Getenv("ARVADOS_API_HOST")
-var _ = check.Suite(&IntegrationSuite{})
+var _ = check.Suite(&ServerSuite{})
-// IntegrationSuite tests need an API server and a keep-web server
-type IntegrationSuite struct {
+type ServerSuite struct {
+ IntegrationSuite
testServer *server
}
-func (s *IntegrationSuite) TestNoToken(c *check.C) {
+func (s *ServerSuite) TestNoToken(c *check.C) {
for _, token := range []string{
"",
"bogustoken",
@@ -52,7 +52,7 @@ func (s *IntegrationSuite) TestNoToken(c *check.C) {
// http client instead of forking curl. Just leave enough of an
// integration test to assure that the documented way of invoking curl
// really works against the server.
-func (s *IntegrationSuite) Test404(c *check.C) {
+func (s *ServerSuite) Test404(c *check.C) {
for _, uri := range []string{
// Routing errors (always 404 regardless of what's stored in Keep)
"/",
@@ -81,14 +81,14 @@ func (s *IntegrationSuite) Test404(c *check.C) {
}
}
-func (s *IntegrationSuite) Test1GBFile(c *check.C) {
+func (s *ServerSuite) Test1GBFile(c *check.C) {
if testing.Short() {
c.Skip("skipping 1GB integration test in short mode")
}
s.test100BlockFile(c, 10000000)
}
-func (s *IntegrationSuite) Test100BlockFile(c *check.C) {
+func (s *ServerSuite) Test100BlockFile(c *check.C) {
if testing.Short() {
// 3 MB
s.test100BlockFile(c, 30000)
@@ -98,7 +98,7 @@ func (s *IntegrationSuite) Test100BlockFile(c *check.C) {
}
}
-func (s *IntegrationSuite) test100BlockFile(c *check.C, blocksize int) {
+func make100BlockCollection(c *check.C, blocksize int) (data []byte, uuid string, token string) {
testdata := make([]byte, blocksize)
for i := 0; i < blocksize; i++ {
testdata[i] = byte(' ')
@@ -124,9 +124,12 @@ func (s *IntegrationSuite) test100BlockFile(c *check.C, blocksize int) {
},
}, &coll)
c.Assert(err, check.Equals, nil)
- uuid := coll["uuid"].(string)
+ return testdata, coll["uuid"].(string), arv.ApiToken
+}
- hdr, body, size := s.runCurl(c, arv.ApiToken, uuid+".collections.example.com", "/testdata.bin")
+func (s *ServerSuite) test100BlockFile(c *check.C, blocksize int) {
+ testdata, uuid, token := make100BlockCollection(c, blocksize)
+ hdr, body, size := s.runCurl(c, token, uuid+".collections.example.com", "/testdata.bin")
c.Check(hdr, check.Matches, `(?s)HTTP/1.1 200 OK\r\n.*`)
c.Check(hdr, check.Matches, `(?si).*Content-length: `+fmt.Sprintf("%d00", blocksize)+`\r\n.*`)
c.Check([]byte(body)[:1234], check.DeepEquals, testdata[:1234])
@@ -140,7 +143,7 @@ type curlCase struct {
dataMD5 string
}
-func (s *IntegrationSuite) Test200(c *check.C) {
+func (s *ServerSuite) Test200(c *check.C) {
s.testServer.Config.AnonymousTokens = []string{arvadostest.AnonymousToken}
for _, spec := range []curlCase{
// My collection
@@ -247,7 +250,7 @@ func (s *IntegrationSuite) Test200(c *check.C) {
}
// Return header block and body.
-func (s *IntegrationSuite) runCurl(c *check.C, token, host, uri string, args ...string) (hdr, bodyPart string, bodySize int64) {
+func (s *ServerSuite) runCurl(c *check.C, token, host, uri string, args ...string) (hdr, bodyPart string, bodySize int64) {
curlArgs := []string{"--silent", "--show-error", "--include"}
testHost, testPort, _ := net.SplitHostPort(s.testServer.Addr)
curlArgs = append(curlArgs, "--resolve", host+":"+testPort+":"+testHost)
@@ -290,26 +293,7 @@ func (s *IntegrationSuite) runCurl(c *check.C, token, host, uri string, args ...
return
}
-func (s *IntegrationSuite) SetUpSuite(c *check.C) {
- arvadostest.StartAPI()
- arvadostest.StartKeep(2, true)
-
- arv, err := arvadosclient.MakeArvadosClient()
- c.Assert(err, check.Equals, nil)
- arv.ApiToken = arvadostest.ActiveToken
- kc, err := keepclient.MakeKeepClient(arv)
- c.Assert(err, check.Equals, nil)
- kc.PutB([]byte("Hello world\n"))
- kc.PutB([]byte("foo"))
- kc.PutB([]byte("foobar"))
-}
-
-func (s *IntegrationSuite) TearDownSuite(c *check.C) {
- arvadostest.StopKeep(2)
- arvadostest.StopAPI()
-}
-
-func (s *IntegrationSuite) SetUpTest(c *check.C) {
+func (s *ServerSuite) SetUpTest(c *check.C) {
arvadostest.ResetEnv()
s.testServer = &server{Config: &Config{
Client: arvados.Client{
@@ -322,7 +306,7 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) {
c.Assert(err, check.Equals, nil)
}
-func (s *IntegrationSuite) TearDownTest(c *check.C) {
+func (s *ServerSuite) TearDownTest(c *check.C) {
var err error
if s.testServer != nil {
err = s.testServer.Close()
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list