[ARVADOS] updated: f51b562b9def7f6bc17e0cc52b60ffc2641d40b5
git at public.curoverse.com
git at public.curoverse.com
Fri Jul 17 13:31:17 EDT 2015
Summary of changes:
services/datamanager/keep/keep.go | 21 ++++++++++------
services/datamanager/keep/keep_test.go | 44 ++++++++++++++++------------------
2 files changed, 34 insertions(+), 31 deletions(-)
via f51b562b9def7f6bc17e0cc52b60ffc2641d40b5 (commit)
from f63e86a3270836ab5e5f1de31e28b686ff809739 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit f51b562b9def7f6bc17e0cc52b60ffc2641d40b5
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date: Fri Jul 17 13:32:00 2015 -0400
6221: SendTrashLists() returns errors. Tests updated.
diff --git a/services/datamanager/keep/keep.go b/services/datamanager/keep/keep.go
index 08e54e6..c2c85fb 100644
--- a/services/datamanager/keep/keep.go
+++ b/services/datamanager/keep/keep.go
@@ -5,6 +5,7 @@ package keep
import (
"bufio"
"encoding/json"
+ "errors"
"flag"
"fmt"
"git.curoverse.com/arvados.git/sdk/go/arvadosclient"
@@ -461,9 +462,9 @@ type TrashRequest struct {
type TrashList []TrashRequest
-func SendTrashLists(dataManagerToken string, kc *keepclient.KeepClient, spl map[string]TrashList) {
+func SendTrashLists(dataManagerToken string, kc *keepclient.KeepClient, spl map[string]TrashList) (err []error) {
count := 0
- barrier := make(chan bool)
+ barrier := make(chan error)
client := kc.Client
@@ -472,10 +473,6 @@ func SendTrashLists(dataManagerToken string, kc *keepclient.KeepClient, spl map[
log.Printf("Sending trash list to %v", url)
go (func(url string, v TrashList) {
- defer (func() {
- barrier <- true
- })()
-
pipeReader, pipeWriter := io.Pipe()
go (func() {
enc := json.NewEncoder(pipeWriter)
@@ -486,6 +483,7 @@ func SendTrashLists(dataManagerToken string, kc *keepclient.KeepClient, spl map[
req, err := http.NewRequest("PUT", fmt.Sprintf("%s/trash", url), pipeReader)
if err != nil {
log.Printf("Error creating trash list request for %v error: %v", url, err.Error())
+ barrier <- err
return
}
@@ -496,6 +494,7 @@ func SendTrashLists(dataManagerToken string, kc *keepclient.KeepClient, spl map[
var resp *http.Response
if resp, err = client.Do(req); err != nil {
log.Printf("Error sending trash list to %v error: %v", url, err.Error())
+ barrier <- err
return
}
@@ -503,11 +502,19 @@ func SendTrashLists(dataManagerToken string, kc *keepclient.KeepClient, spl map[
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
+
+ if resp.StatusCode != 200 {
+ barrier <- errors.New(fmt.Sprintf("Got HTTP code %v", resp.StatusCode))
+ } else {
+ barrier <- nil
+ }
})(url, v)
}
for i := 0; i < count; i += 1 {
- <-barrier
+ err = append(err, <-barrier)
}
+
+ return err
}
diff --git a/services/datamanager/keep/keep_test.go b/services/datamanager/keep/keep_test.go
index 85f704c..2bf37c8 100644
--- a/services/datamanager/keep/keep_test.go
+++ b/services/datamanager/keep/keep_test.go
@@ -39,9 +39,11 @@ func (s *KeepSuite) TestSendTrashLists(c *C) {
map[string]string{"xxxx": server.URL},
map[string]string{})
- SendTrashLists("", &kc, tl)
+ err := SendTrashLists("", &kc, tl)
server.Close()
+ c.Check(err[0], IsNil)
+
c.Check(th.request,
DeepEquals,
tl[server.URL])
@@ -52,14 +54,14 @@ type TestHandlerError struct {
}
func (this *TestHandlerError) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
- http.Error(writer, "I'm a teapot", 405)
+ http.Error(writer, "I'm a teapot", 418)
}
-func (s *KeepSuite) TestSendTrashListError(c *C) {
- // Server responds with an error
-
- th := TestHandlerError{}
- server := httptest.NewServer(&th)
+func sendTrashListError(c *C, close_early bool, th http.Handler) {
+ server := httptest.NewServer(th)
+ if close_early {
+ server.Close()
+ }
tl := map[string]TrashList{
server.URL: TrashList{TrashRequest{"000000000000000000000000deadbeef", 99}}}
@@ -69,24 +71,18 @@ func (s *KeepSuite) TestSendTrashListError(c *C) {
map[string]string{"xxxx": server.URL},
map[string]string{})
- SendTrashLists("", &kc, tl)
- server.Close()
-}
-
-func (s *KeepSuite) TestSendTrashListError2(c *C) {
- // Server is not reachable
-
- th := TestHandler{}
- server := httptest.NewServer(&th)
- server.Close()
+ err := SendTrashLists("", &kc, tl)
+ if !close_early {
+ server.Close()
+ }
- tl := map[string]TrashList{
- server.URL: TrashList{TrashRequest{"000000000000000000000000deadbeef", 99}}}
+ c.Check(err[0], NotNil)
+}
- kc := keepclient.KeepClient{Client: &http.Client{}}
- kc.SetServiceRoots(map[string]string{"xxxx": server.URL},
- map[string]string{"xxxx": server.URL},
- map[string]string{})
+func (s *KeepSuite) TestSendTrashListErrorResponse(c *C) {
+ sendTrashListError(c, false, &TestHandlerError{})
+}
- SendTrashLists("", &kc, tl)
+func (s *KeepSuite) TestSendTrashListUnreachable(c *C) {
+ sendTrashListError(c, true, &TestHandler{})
}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list