3761: move test assertions from teardown method into performTest function for better...
authorRadhika Chippada <radhika@curoverse.com>
Fri, 6 Mar 2015 19:21:58 +0000 (14:21 -0500)
committerRadhika Chippada <radhika@curoverse.com>
Fri, 6 Mar 2015 19:21:58 +0000 (14:21 -0500)
services/keepstore/pull_worker.go
services/keepstore/pull_worker_test.go

index 46b933c5e0503824a2d02b4a60d1390cd5515eaa..5a631e01587073fe5322700cf5e89e7924d88a9f 100644 (file)
@@ -40,6 +40,9 @@ func RunPullWorker(pullq *WorkQueue, keepClient keepclient.KeepClient) {
                Write to storage
 */
 func Pull(pullRequest PullRequest, keepClient keepclient.KeepClient) (err error) {
+       token := GenerateRandomApiToken()
+       keepClient.Arvados.ApiToken = token
+
        service_roots := make(map[string]string)
        for _, addr := range pullRequest.Servers {
                service_roots[addr] = addr
@@ -48,7 +51,7 @@ func Pull(pullRequest PullRequest, keepClient keepclient.KeepClient) (err error)
 
        // Generate signature with a random token
        expires_at := time.Now().Add(60 * time.Second)
-       signedLocator := SignLocator(pullRequest.Locator, GenerateRandomApiToken(), expires_at)
+       signedLocator := SignLocator(pullRequest.Locator, token, expires_at)
 
        reader, contentLen, _, err := GetContent(signedLocator, keepClient)
        if err != nil {
index 8c99a14227e3d713c67d2cb7f0297ae91daaee6e..eb748501516a0095fe537fcd9a6584cf0326d2df 100644 (file)
@@ -43,31 +43,6 @@ func (s *PullWorkerTestSuite) SetUpTest(c *C) {
        processedPullLists = make(map[string]string)
 }
 
-func (s *PullWorkerTestSuite) TearDownTest(c *C) {
-       expectWorkerChannelEmpty(c, pullq.NextItem)
-
-       if currentTestData.name == "TestPullWorker_pull_list_with_two_items_latest_replacing_old" {
-               c.Assert(len(testPullLists), Equals, 2)
-               c.Assert(len(processedPullLists), Equals, 1)
-               c.Assert(testPullLists["Added_before_actual_test_item"], NotNil)
-               c.Assert(testPullLists["TestPullWorker_pull_list_with_two_items_latest_replacing_old"], NotNil)
-               c.Assert(processedPullLists["TestPullWorker_pull_list_with_two_items_latest_replacing_old"], NotNil)
-       }
-
-       if currentTestData.read_error {
-               c.Assert(readError, NotNil)
-       } else {
-               c.Assert(readError, IsNil)
-               c.Assert(readContent, Equals, READ_CONTENT)
-               if currentTestData.put_error {
-                       c.Assert(putError, NotNil)
-               } else {
-                       c.Assert(putError, IsNil)
-                       c.Assert(string(putContent), Equals, READ_CONTENT)
-               }
-       }
-}
-
 // Since keepstore does not come into picture in tests,
 // we need to explicitly start the goroutine in tests.
 func RunTestPullWorker(c *C) {
@@ -283,6 +258,36 @@ func performTest(testData PullWorkerTestData, c *C) {
        response := IssueRequest(&testData.req)
        c.Assert(testData.response_code, Equals, response.Code)
        c.Assert(testData.response_body, Equals, response.Body.String())
+
+       expectWorkerChannelEmpty(c, pullq.NextItem)
+
+       pullq.Close()
+
+       if testData.name == "TestPullWorker_pull_list_with_two_items_latest_replacing_old" {
+               c.Assert(len(testPullLists), Equals, 2)
+               c.Assert(len(processedPullLists), Equals, 1)
+               c.Assert(testPullLists["Added_before_actual_test_item"], NotNil)
+               c.Assert(testPullLists["TestPullWorker_pull_list_with_two_items_latest_replacing_old"], NotNil)
+               c.Assert(processedPullLists["TestPullWorker_pull_list_with_two_items_latest_replacing_old"], NotNil)
+       } else {
+               c.Assert(len(testPullLists), Equals, 1)
+               c.Assert(len(processedPullLists), Equals, 1)
+               c.Assert(testPullLists[testData.name], NotNil)
+       }
+
+       if testData.read_error {
+               c.Assert(readError, NotNil)
+       } else {
+               c.Assert(readError, IsNil)
+               c.Assert(readContent, Equals, READ_CONTENT)
+               if testData.put_error {
+                       c.Assert(putError, NotNil)
+               } else {
+                       c.Assert(putError, IsNil)
+                       c.Assert(string(putContent), Equals, READ_CONTENT)
+               }
+       }
+
 }
 
 type ClosingBuffer struct {