Merge branch 'master' into 4717-read-only-keep-services-flag
[arvados.git] / services / keepproxy / keepproxy_test.go
index ccbd7d8790c5042566aff7bb4941f56a0c91e26a..b70b9333688b47228e1a49af69129e40daa1412b 100644 (file)
@@ -110,17 +110,21 @@ func runProxy(c *C, args []string, port int, bogusClientToken bool) keepclient.K
        arv, err := arvadosclient.MakeArvadosClient()
        c.Assert(err, Equals, nil)
        kc := keepclient.KeepClient{
-               Arvados: &arv,
+               Arvados:       &arv,
                Want_replicas: 2,
-               Using_proxy: true,
-               Client: &http.Client{},
+               Using_proxy:   true,
+               Client:        &http.Client{},
        }
-       kc.SetServiceRoots(map[string]string{
+       locals := map[string]string{
                "proxy": fmt.Sprintf("http://localhost:%v", port),
-       })
+       }
+       writables := map[string]string{
+               "proxy": fmt.Sprintf("http://localhost:%v", port),
+       }
+       kc.SetServiceRoots(locals, nil, writables)
        c.Check(kc.Using_proxy, Equals, true)
-       c.Check(len(kc.ServiceRoots()), Equals, 1)
-       for _, root := range kc.ServiceRoots() {
+       c.Check(len(kc.LocalRoots()), Equals, 1)
+       for _, root := range kc.LocalRoots() {
                c.Check(root, Equals, fmt.Sprintf("http://localhost:%v", port))
        }
        log.Print("keepclient created")
@@ -154,8 +158,8 @@ func (s *ServerRequiredSuite) TestPutAskGet(c *C) {
        c.Assert(err, Equals, nil)
        c.Check(kc.Arvados.External, Equals, true)
        c.Check(kc.Using_proxy, Equals, true)
-       c.Check(len(kc.ServiceRoots()), Equals, 1)
-       for _, root := range kc.ServiceRoots() {
+       c.Check(len(kc.LocalRoots()), Equals, 1)
+       for _, root := range kc.LocalRoots() {
                c.Check(root, Equals, "http://localhost:29950")
        }
        os.Setenv("ARVADOS_EXTERNAL_CLIENT", "")
@@ -169,9 +173,25 @@ func (s *ServerRequiredSuite) TestPutAskGet(c *C) {
        {
                _, _, err := kc.Ask(hash)
                c.Check(err, Equals, keepclient.BlockNotFound)
-               log.Print("Ask 1")
+               log.Print("Finished Ask (expected BlockNotFound)")
        }
 
+       {
+               reader, _, _, err := kc.Get(hash)
+               c.Check(reader, Equals, nil)
+               c.Check(err, Equals, keepclient.BlockNotFound)
+               log.Print("Finished Get (expected BlockNotFound)")
+       }
+
+       // Note in bug #5309 among other errors keepproxy would set
+       // Content-Length incorrectly on the 404 BlockNotFound response, this
+       // would result in a protocol violation that would prevent reuse of the
+       // connection, which would manifest by the next attempt to use the
+       // connection (in this case the PutB below) failing.  So to test for
+       // that bug it's necessary to trigger an error response (such as
+       // BlockNotFound) and then do something else with the same httpClient
+       // connection.
+
        {
                var rep int
                var err error
@@ -179,14 +199,14 @@ func (s *ServerRequiredSuite) TestPutAskGet(c *C) {
                c.Check(hash2, Matches, fmt.Sprintf(`^%s\+3(\+.+)?$`, hash))
                c.Check(rep, Equals, 2)
                c.Check(err, Equals, nil)
-               log.Print("PutB")
+               log.Print("Finished PutB (expected success)")
        }
 
        {
                blocklen, _, err := kc.Ask(hash2)
                c.Assert(err, Equals, nil)
                c.Check(blocklen, Equals, int64(3))
-               log.Print("Ask 2")
+               log.Print("Finished Ask (expected success)")
        }
 
        {
@@ -195,7 +215,7 @@ func (s *ServerRequiredSuite) TestPutAskGet(c *C) {
                all, err := ioutil.ReadAll(reader)
                c.Check(all, DeepEquals, []byte("foo"))
                c.Check(blocklen, Equals, int64(3))
-               log.Print("Get")
+               log.Print("Finished Get (expected success)")
        }
 
        {
@@ -205,7 +225,7 @@ func (s *ServerRequiredSuite) TestPutAskGet(c *C) {
                c.Check(hash2, Matches, `^d41d8cd98f00b204e9800998ecf8427e\+0(\+.+)?$`)
                c.Check(rep, Equals, 2)
                c.Check(err, Equals, nil)
-               log.Print("PutB zero block")
+               log.Print("Finished PutB zero block")
        }
 
        {
@@ -214,7 +234,7 @@ func (s *ServerRequiredSuite) TestPutAskGet(c *C) {
                all, err := ioutil.ReadAll(reader)
                c.Check(all, DeepEquals, []byte(""))
                c.Check(blocklen, Equals, int64(0))
-               log.Print("Get zero block")
+               log.Print("Finished Get zero block")
        }
 
        log.Print("TestPutAndGet done")
@@ -370,3 +390,19 @@ func (s *ServerRequiredSuite) TestPostWithoutHash(c *C) {
                        fmt.Sprintf("%x+%d", md5.Sum([]byte("qux")), 3))
        }
 }
+
+func (s *ServerRequiredSuite) TestStripHint(c *C) {
+       c.Check(removeHint.ReplaceAllString("http://keep.zzzzz.arvadosapi.com:25107/2228819a18d3727630fa30c81853d23f+67108864+A37b6ab198qqqq28d903b975266b23ee711e1852c@55635f73+K@zzzzz", "$1"),
+               Equals,
+               "http://keep.zzzzz.arvadosapi.com:25107/2228819a18d3727630fa30c81853d23f+67108864+A37b6ab198qqqq28d903b975266b23ee711e1852c@55635f73")
+       c.Check(removeHint.ReplaceAllString("http://keep.zzzzz.arvadosapi.com:25107/2228819a18d3727630fa30c81853d23f+67108864+K@zzzzz+A37b6ab198qqqq28d903b975266b23ee711e1852c@55635f73", "$1"),
+               Equals,
+               "http://keep.zzzzz.arvadosapi.com:25107/2228819a18d3727630fa30c81853d23f+67108864+A37b6ab198qqqq28d903b975266b23ee711e1852c@55635f73")
+       c.Check(removeHint.ReplaceAllString("http://keep.zzzzz.arvadosapi.com:25107/2228819a18d3727630fa30c81853d23f+67108864+A37b6ab198qqqq28d903b975266b23ee711e1852c@55635f73+K@zzzzz-zzzzz-zzzzzzzzzzzzzzz", "$1"),
+               Equals,
+               "http://keep.zzzzz.arvadosapi.com:25107/2228819a18d3727630fa30c81853d23f+67108864+A37b6ab198qqqq28d903b975266b23ee711e1852c@55635f73+K@zzzzz-zzzzz-zzzzzzzzzzzzzzz")
+       c.Check(removeHint.ReplaceAllString("http://keep.zzzzz.arvadosapi.com:25107/2228819a18d3727630fa30c81853d23f+67108864+K@zzzzz-zzzzz-zzzzzzzzzzzzzzz+A37b6ab198qqqq28d903b975266b23ee711e1852c@55635f73", "$1"),
+               Equals,
+               "http://keep.zzzzz.arvadosapi.com:25107/2228819a18d3727630fa30c81853d23f+67108864+K@zzzzz-zzzzz-zzzzzzzzzzzzzzz+A37b6ab198qqqq28d903b975266b23ee711e1852c@55635f73")
+
+}