7492: add a test that simulates keep server unavailable error.
authorradhika <radhika@curoverse.com>
Tue, 27 Oct 2015 23:48:47 +0000 (19:48 -0400)
committerradhika <radhika@curoverse.com>
Tue, 27 Oct 2015 23:48:47 +0000 (19:48 -0400)
services/keepproxy/keepproxy_test.go

index 6303122e345414d11b8d75c0ebd5be3eb5c428be..997163eca42c965f41109af3ad51de22e65c80d3 100644 (file)
@@ -30,6 +30,12 @@ var _ = Suite(&ServerRequiredSuite{})
 // Tests that require the Keep server running
 type ServerRequiredSuite struct{}
 
+// Gocheck boilerplate
+var _ = Suite(&NoKeepServerSuite{})
+
+// Test with no keepserver to simulate errors
+type NoKeepServerSuite struct{}
+
 // Wait (up to 1 second) for keepproxy to listen on a port. This
 // avoids a race condition where we hit a "connection refused" error
 // because we start testing the proxy too soon.
@@ -65,6 +71,18 @@ func (s *ServerRequiredSuite) TearDownSuite(c *C) {
        arvadostest.StopAPI()
 }
 
+func (s *NoKeepServerSuite) SetUpSuite(c *C) {
+       arvadostest.StartAPI()
+}
+
+func (s *NoKeepServerSuite) SetUpTest(c *C) {
+       arvadostest.ResetEnv()
+}
+
+func (s *NoKeepServerSuite) TearDownSuite(c *C) {
+       arvadostest.StopAPI()
+}
+
 func setupProxyService() {
 
        client := &http.Client{Transport: &http.Transport{
@@ -519,7 +537,7 @@ func (s *ServerRequiredSuite) TestPutAskGetInvalidToken(c *C) {
        }
 }
 
-func (s *ServerRequiredSuite) TestPutAskGetConnectionError(c *C) {
+func (s *ServerRequiredSuite) TestAskGetKeepProxyConnectionError(c *C) {
        arv, err := arvadosclient.MakeArvadosClient()
        c.Assert(err, Equals, nil)
 
@@ -545,3 +563,24 @@ func (s *ServerRequiredSuite) TestPutAskGetConnectionError(c *C) {
        c.Check(errNotFound.Temporary(), Equals, true)
        c.Assert(strings.Contains(err.Error(), "connection refused"), Equals, true)
 }
+
+func (s *NoKeepServerSuite) TestAskGetNoKeepServerError(c *C) {
+       kc := runProxy(c, []string{"keepproxy"}, 29999, false)
+       waitForListener()
+       defer closeListener()
+
+       // Ask should result in temporary connection refused error
+       hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
+       _, _, err := kc.Ask(hash)
+       c.Check(err, NotNil)
+       errNotFound, _ := err.(*keepclient.ErrNotFound)
+       c.Check(errNotFound.Temporary(), Equals, true)
+       c.Assert(strings.Contains(err.Error(), "HTTP 502"), Equals, true)
+
+       // Get should result in temporary connection refused error
+       _, _, _, err = kc.Get(hash)
+       c.Check(err, NotNil)
+       errNotFound, _ = err.(*keepclient.ErrNotFound)
+       c.Check(errNotFound.Temporary(), Equals, true)
+       c.Assert(strings.Contains(err.Error(), "HTTP 502"), Equals, true)
+}