4 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
5 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
19 // Gocheck boilerplate
20 func Test(t *testing.T) {
24 var _ = Suite(&TestSuite{})
25 var _ = Suite(&MockArvadosServerSuite{})
27 type TestSuite struct{}
28 type MockArvadosServerSuite struct{}
30 var initialArgs []string
32 func (s *TestSuite) SetUpSuite(c *C) {
34 arvadostest.StartAPI()
37 func (s *TestSuite) TearDownSuite(c *C) {
41 func (s *TestSuite) SetUpTest(c *C) {
42 args := []string{"crunch-dispatch-local"}
46 arv, err = arvadosclient.MakeArvadosClient()
48 c.Fatalf("Error making arvados client: %s", err)
52 func (s *TestSuite) TearDownTest(c *C) {
53 arvadostest.ResetEnv()
57 func (s *MockArvadosServerSuite) TearDownTest(c *C) {
58 arvadostest.ResetEnv()
61 func (s *TestSuite) Test_doMain(c *C) {
62 args := []string{"-poll-interval", "2", "-container-priority-poll-interval", "1", "-crunch-run-command", "echo"}
63 os.Args = append(os.Args, args...)
66 time.Sleep(5 * time.Second)
67 sigChan <- syscall.SIGINT
73 // There should be no queued containers now
74 params := arvadosclient.Dict{
75 "filters": [][]string{[]string{"state", "=", "Queued"}},
77 var containers ContainerList
78 err = arv.List("containers", params, &containers)
80 c.Assert(len(containers.Items), Equals, 0)
82 // Previously "Queued" container should now be in "Complete" state
83 var container Container
84 err = arv.Get("containers", "zzzzz-dz642-queuedcontainer", nil, &container)
86 c.Check(container.State, Equals, "Complete")
89 func (s *MockArvadosServerSuite) Test_APIErrorGettingContainers(c *C) {
90 apiStubResponses := make(map[string]arvadostest.StubResponse)
91 apiStubResponses["/arvados/v1/containers"] = arvadostest.StubResponse{500, string(`{}`)}
93 testWithServerStub(c, apiStubResponses, "echo", "Error getting list of queued containers")
96 func (s *MockArvadosServerSuite) Test_APIErrorUpdatingContainerState(c *C) {
97 apiStubResponses := make(map[string]arvadostest.StubResponse)
98 apiStubResponses["/arvados/v1/containers"] =
99 arvadostest.StubResponse{200, string(`{"items_available":1, "items":[{"uuid":"zzzzz-dz642-xxxxxxxxxxxxxx1"}]}`)}
100 apiStubResponses["/arvados/v1/containers/zzzzz-dz642-xxxxxxxxxxxxxx1"] =
101 arvadostest.StubResponse{500, string(`{}`)}
103 testWithServerStub(c, apiStubResponses, "echo", "Error updating container zzzzz-dz642-xxxxxxxxxxxxxx1 to 'Locked' state")
106 func (s *MockArvadosServerSuite) Test_ContainerStillInRunningAfterRun(c *C) {
107 apiStubResponses := make(map[string]arvadostest.StubResponse)
108 apiStubResponses["/arvados/v1/containers"] =
109 arvadostest.StubResponse{200, string(`{"items_available":1, "items":[{"uuid":"zzzzz-dz642-xxxxxxxxxxxxxx2"}]}`)}
110 apiStubResponses["/arvados/v1/containers/zzzzz-dz642-xxxxxxxxxxxxxx2"] =
111 arvadostest.StubResponse{200, string(`{"uuid":"zzzzz-dz642-xxxxxxxxxxxxxx2", "state":"Running", "priority":1}`)}
113 testWithServerStub(c, apiStubResponses, "echo",
114 "After crunch-run process termination, the state is still 'Running' for zzzzz-dz642-xxxxxxxxxxxxxx2")
117 func (s *MockArvadosServerSuite) Test_ErrorRunningContainer(c *C) {
118 apiStubResponses := make(map[string]arvadostest.StubResponse)
119 apiStubResponses["/arvados/v1/containers"] =
120 arvadostest.StubResponse{200, string(`{"items_available":1, "items":[{"uuid":"zzzzz-dz642-xxxxxxxxxxxxxx3"}]}`)}
121 apiStubResponses["/arvados/v1/containers/zzzzz-dz642-xxxxxxxxxxxxxx3"] =
122 arvadostest.StubResponse{200, string(`{"uuid":"zzzzz-dz642-xxxxxxxxxxxxxx3", "state":"Running", "priority":1}`)}
124 testWithServerStub(c, apiStubResponses, "nosuchcommand", "Error starting crunch-run for zzzzz-dz642-xxxxxxxxxxxxxx3")
127 func testWithServerStub(c *C, apiStubResponses map[string]arvadostest.StubResponse, crunchCmd string, expected string) {
128 apiStub := arvadostest.ServerStub{apiStubResponses}
130 api := httptest.NewServer(&apiStub)
133 arv = arvadosclient.ArvadosClient{
135 ApiServer: api.URL[7:],
137 Client: &http.Client{Transport: &http.Transport{}},
141 buf := bytes.NewBuffer(nil)
143 defer log.SetOutput(os.Stderr)
146 time.Sleep(2 * time.Second)
147 sigChan <- syscall.SIGTERM
150 runQueuedContainers(time.Second, time.Second, crunchCmd)
152 // Wait for all running crunch jobs to complete / terminate
155 c.Check(buf.String(), Matches, `(?ms).*`+expected+`.*`)