[ARVADOS] updated: c7200a367392801491134e97192840b8b20fc90b
git at public.curoverse.com
git at public.curoverse.com
Thu Mar 5 18:02:25 EST 2015
Summary of changes:
services/keepstore/pull_worker_test.go | 163 +++++++++++++++++++--------------
1 file changed, 96 insertions(+), 67 deletions(-)
via c7200a367392801491134e97192840b8b20fc90b (commit)
via a882872e54809a5f5a19fc5673f7dd53655f1cb8 (commit)
from 314b31df6b5f54e0e62dcc3d138ab32f0339d34c (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 c7200a367392801491134e97192840b8b20fc90b
Author: Radhika Chippada <radhika at curoverse.com>
Date: Thu Mar 5 17:59:59 2015 -0500
3761: Improve the tests to RunTestPullWorker for each test and verify the queue is empty at the end of test.
Add a test that puts two items on the queue and verifies that old item is overwritten by the new item.
diff --git a/services/keepstore/pull_worker_test.go b/services/keepstore/pull_worker_test.go
index 7614101..8c99a14 100644
--- a/services/keepstore/pull_worker_test.go
+++ b/services/keepstore/pull_worker_test.go
@@ -8,9 +8,7 @@ import (
. "gopkg.in/check.v1"
"io"
"net/http"
- "strings"
"testing"
- "time"
)
type PullWorkerTestSuite struct{}
@@ -33,18 +31,6 @@ var currentTestData PullWorkerTestData
const READ_CONTENT = "Hi!"
-func RunTestPullWorker(c *C) {
- // Since keepstore does not come into picture in tests,
- // we need to explicitly start the goroutine in tests.
- arv, err := arvadosclient.MakeArvadosClient()
- c.Assert(err, Equals, nil)
- keepClient, err := keepclient.MakeKeepClient(&arv)
- c.Assert(err, Equals, nil)
-
- pullq = NewWorkQueue()
- go RunPullWorker(pullq, keepClient)
-}
-
func (s *PullWorkerTestSuite) SetUpTest(c *C) {
readContent = ""
readError = nil
@@ -52,19 +38,21 @@ func (s *PullWorkerTestSuite) SetUpTest(c *C) {
putError = nil
// When a new pull request arrives, the old one will be overwritten.
- // This behavior is simulated with delay tests below.
+ // This behavior is verified using these maps in the "TestPullWorker_pull_list_with_two_items_latest_replacing_old"
testPullLists = make(map[string]string)
processedPullLists = make(map[string]string)
}
func (s *PullWorkerTestSuite) TearDownTest(c *C) {
- time.Sleep(20 * time.Millisecond)
expectWorkerChannelEmpty(c, pullq.NextItem)
- // give the channel some time to read and process all pull list entries
- // time.Sleep(1000 * time.Millisecond)
- // expectWorkerChannelEmpty(c, pullq.NextItem)
- // c.Assert(len(processedPullLists), Not(Equals), len(testPullLists))
+ 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)
@@ -80,6 +68,18 @@ func (s *PullWorkerTestSuite) TearDownTest(c *C) {
}
}
+// Since keepstore does not come into picture in tests,
+// we need to explicitly start the goroutine in tests.
+func RunTestPullWorker(c *C) {
+ arv, err := arvadosclient.MakeArvadosClient()
+ c.Assert(err, Equals, nil)
+ keepClient, err := keepclient.MakeKeepClient(&arv)
+ c.Assert(err, Equals, nil)
+
+ pullq = NewWorkQueue()
+ go RunPullWorker(pullq, keepClient)
+}
+
var first_pull_list = []byte(`[
{
"locator":"locator1",
@@ -150,44 +150,6 @@ func (s *PullWorkerTestSuite) TestPullWorker_pull_list_with_one_locator(c *C) {
performTest(testData, c)
}
-// When a new pull request arrives, the old one will be overwritten.
-// Simulate this behavior by inducing delay in GetContent for the delay test(s).
-// To ensure this delay test is not the last one executed and
-// hence we cannot verify this behavior, let's run the delay test twice.
-func (s *PullWorkerTestSuite) TestPullWorker_pull_list_with_one_locator_with_delay_1(c *C) {
- defer teardown()
-
- data_manager_token = "DATA MANAGER TOKEN"
- testData := PullWorkerTestData{
- name: "TestPullWorker_pull_list_with_one_locator_with_delay_1",
- req: RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
- response_code: http.StatusOK,
- response_body: "Received 1 pull requests\n",
- read_content: "hola",
- read_error: false,
- put_error: false,
- }
-
- performTest(testData, c)
-}
-
-func (s *PullWorkerTestSuite) TestPullWorker_pull_list_with_one_locator_with_delay_2(c *C) {
- defer teardown()
-
- data_manager_token = "DATA MANAGER TOKEN"
- testData := PullWorkerTestData{
- name: "TestPullWorker_pull_list_with_one_locator_with_delay_2",
- req: RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
- response_code: http.StatusOK,
- response_body: "Received 1 pull requests\n",
- read_content: "hola",
- read_error: false,
- put_error: false,
- }
-
- performTest(testData, c)
-}
-
func (s *PullWorkerTestSuite) TestPullWorker_error_on_get_one_locator(c *C) {
defer teardown()
@@ -256,21 +218,41 @@ func (s *PullWorkerTestSuite) TestPullWorker_error_on_put_two_locators(c *C) {
performTest(testData, c)
}
+// When a new pull request arrives, the old one is replaced. This test
+// is used to check that behavior by first putting an item on the queue,
+// and then performing the test. Thus the "testPullLists" has two entries;
+// however, processedPullLists will see only the newest item in the list.
+func (s *PullWorkerTestSuite) TestPullWorker_pull_list_with_two_items_latest_replacing_old(c *C) {
+ defer teardown()
+
+ var firstInput = []int{1}
+ pullq = NewWorkQueue()
+ pullq.ReplaceQueue(makeTestWorkList(firstInput))
+ testPullLists["Added_before_actual_test_item"] = string(1)
+
+ data_manager_token = "DATA MANAGER TOKEN"
+ testData := PullWorkerTestData{
+ name: "TestPullWorker_pull_list_with_two_items_latest_replacing_old",
+ req: RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
+ response_code: http.StatusOK,
+ response_body: "Received 1 pull requests\n",
+ read_content: "hola",
+ read_error: false,
+ put_error: false,
+ }
+
+ performTest(testData, c)
+}
+
func performTest(testData PullWorkerTestData, c *C) {
RunTestPullWorker(c)
currentTestData = testData
testPullLists[testData.name] = testData.response_body
- // We need to make sure the tests have a slight delay so that we can verify the pull list channel overwrites.
- // time.Sleep(25 * time.Millisecond)
-
// Override GetContent to mock keepclient Get functionality
GetContent = func(signedLocator string, keepClient keepclient.KeepClient) (
reader io.ReadCloser, contentLength int64, url string, err error) {
- if strings.HasPrefix(testData.name, "TestPullWorker_pull_list_with_one_locator_with_delay_1") {
- // time.Sleep(100 * time.Millisecond)
- }
processedPullLists[testData.name] = testData.response_body
if testData.read_error {
@@ -282,7 +264,7 @@ func performTest(testData PullWorkerTestData, c *C) {
cb := &ClosingBuffer{bytes.NewBufferString(readContent)}
var rc io.ReadCloser
rc = cb
- return rc, 3, "", nil
+ return rc, int64(len(READ_CONTENT)), "", nil
}
}
@@ -318,3 +300,11 @@ func expectWorkerChannelEmpty(c *C, workerChannel <-chan interface{}) {
default:
}
}
+
+func expectWorkerChannelNotEmpty(c *C, workerChannel <-chan interface{}) {
+ select {
+ case item := <-workerChannel:
+ c.Fatalf("Received value (%v) from channel that was expected to be empty", item)
+ default:
+ }
+}
commit a882872e54809a5f5a19fc5673f7dd53655f1cb8
Author: Radhika Chippada <radhika at curoverse.com>
Date: Thu Mar 5 16:12:39 2015 -0500
3761: verify ReadContent and PutContent outputs.
diff --git a/services/keepstore/pull_worker_test.go b/services/keepstore/pull_worker_test.go
index 09fdba9..7614101 100644
--- a/services/keepstore/pull_worker_test.go
+++ b/services/keepstore/pull_worker_test.go
@@ -13,9 +13,6 @@ import (
"time"
)
-var testPullLists map[string]string
-var processedPullLists map[string]string
-
type PullWorkerTestSuite struct{}
// Gocheck boilerplate
@@ -26,14 +23,33 @@ func TestPullWorker(t *testing.T) {
// Gocheck boilerplate
var _ = Suite(&PullWorkerTestSuite{})
-func (s *PullWorkerTestSuite) SetUpSuite(c *C) {
+var testPullLists map[string]string
+var processedPullLists map[string]string
+var readContent string
+var readError error
+var putContent []byte
+var putError error
+var currentTestData PullWorkerTestData
+
+const READ_CONTENT = "Hi!"
+
+func RunTestPullWorker(c *C) {
// Since keepstore does not come into picture in tests,
// we need to explicitly start the goroutine in tests.
arv, err := arvadosclient.MakeArvadosClient()
c.Assert(err, Equals, nil)
keepClient, err := keepclient.MakeKeepClient(&arv)
c.Assert(err, Equals, nil)
+
+ pullq = NewWorkQueue()
go RunPullWorker(pullq, keepClient)
+}
+
+func (s *PullWorkerTestSuite) SetUpTest(c *C) {
+ readContent = ""
+ readError = nil
+ putContent = []byte("")
+ putError = nil
// When a new pull request arrives, the old one will be overwritten.
// This behavior is simulated with delay tests below.
@@ -41,13 +57,27 @@ func (s *PullWorkerTestSuite) SetUpSuite(c *C) {
processedPullLists = make(map[string]string)
}
-func (s *PullWorkerTestSuite) TearDownSuite(c *C) {
- // give the channel some time to read and process all pull list entries
- time.Sleep(1000 * time.Millisecond)
-
+func (s *PullWorkerTestSuite) TearDownTest(c *C) {
+ time.Sleep(20 * time.Millisecond)
expectWorkerChannelEmpty(c, pullq.NextItem)
- c.Assert(len(processedPullLists), Not(Equals), len(testPullLists))
+ // give the channel some time to read and process all pull list entries
+ // time.Sleep(1000 * time.Millisecond)
+ // expectWorkerChannelEmpty(c, pullq.NextItem)
+ // c.Assert(len(processedPullLists), Not(Equals), len(testPullLists))
+
+ 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)
+ }
+ }
}
var first_pull_list = []byte(`[
@@ -227,23 +257,29 @@ func (s *PullWorkerTestSuite) TestPullWorker_error_on_put_two_locators(c *C) {
}
func performTest(testData PullWorkerTestData, c *C) {
+ RunTestPullWorker(c)
+
+ currentTestData = testData
testPullLists[testData.name] = testData.response_body
// We need to make sure the tests have a slight delay so that we can verify the pull list channel overwrites.
- time.Sleep(25 * time.Millisecond)
+ // time.Sleep(25 * time.Millisecond)
// Override GetContent to mock keepclient Get functionality
GetContent = func(signedLocator string, keepClient keepclient.KeepClient) (
reader io.ReadCloser, contentLength int64, url string, err error) {
- if strings.HasPrefix(testData.name, "TestPullWorker_pull_list_with_one_locator_with_delay") {
- time.Sleep(100 * time.Millisecond)
+ if strings.HasPrefix(testData.name, "TestPullWorker_pull_list_with_one_locator_with_delay_1") {
+ // time.Sleep(100 * time.Millisecond)
}
processedPullLists[testData.name] = testData.response_body
if testData.read_error {
- return nil, 0, "", errors.New("Error getting data")
+ err = errors.New("Error getting data")
+ readError = err
+ return nil, 0, "", err
} else {
- cb := &ClosingBuffer{bytes.NewBufferString("Hi!")}
+ readContent = READ_CONTENT
+ cb := &ClosingBuffer{bytes.NewBufferString(readContent)}
var rc io.ReadCloser
rc = cb
return rc, 3, "", nil
@@ -253,8 +289,11 @@ func performTest(testData PullWorkerTestData, c *C) {
// Override PutContent to mock PutBlock functionality
PutContent = func(content []byte, locator string) (err error) {
if testData.put_error {
- return errors.New("Error putting data")
+ err = errors.New("Error putting data")
+ putError = err
+ return err
} else {
+ putContent = content
return nil
}
}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list