Merge branch '10700-dispatch'
[arvados.git] / services / crunch-dispatch-slurm / crunch-dispatch-slurm_test.go
index 6692f7f80e341fecfeec5cab1a3dba6ddb3d27a6..8809e7bcc6fc10847ab84da1270387c6c9eb3dd3 100644 (file)
@@ -81,7 +81,8 @@ func (s *TestSuite) TestIntegrationCancel(c *C) {
                return exec.Command("echo")
        }
 
-       container := s.integrationTest(c, func() *exec.Cmd { return exec.Command("echo", "zzzzz-dz642-queuedcontainer") },
+       container := s.integrationTest(c,
+               func() *exec.Cmd { return exec.Command("echo", "zzzzz-dz642-queuedcontainer") },
                []string(nil),
                func(dispatcher *dispatch.Dispatcher, container arvados.Container) {
                        dispatcher.UpdateState(container.UUID, dispatch.Running)
@@ -134,7 +135,7 @@ func (s *TestSuite) integrationTest(c *C,
        }(squeueCmd)
        squeueCmd = newSqueueCmd
 
-       // There should be no queued containers now
+       // There should be one queued container
        params := arvadosclient.Dict{
                "filters": [][]string{{"state", "=", "Queued"}},
        }
@@ -143,27 +144,26 @@ func (s *TestSuite) integrationTest(c *C,
        c.Check(err, IsNil)
        c.Check(len(containers.Items), Equals, 1)
 
-       config.CrunchRunCommand = []string{"echo"}
+       theConfig.CrunchRunCommand = []string{"echo"}
 
-       doneProcessing := make(chan struct{})
        dispatcher := dispatch.Dispatcher{
-               Arv:          arv,
-               PollInterval: time.Duration(1) * time.Second,
+               Arv:        arv,
+               PollPeriod: time.Duration(1) * time.Second,
                RunContainer: func(dispatcher *dispatch.Dispatcher,
                        container arvados.Container,
                        status chan arvados.Container) {
                        go runContainer(dispatcher, container)
                        run(dispatcher, container, status)
-                       doneProcessing <- struct{}{}
+                       dispatcher.Stop()
                },
-               DoneProcessing: doneProcessing}
+       }
 
-       squeueUpdater.StartMonitor(time.Duration(500) * time.Millisecond)
+       sqCheck = SqueueChecker{Period: 500 * time.Millisecond}
 
-       err = dispatcher.RunDispatcher()
+       err = dispatcher.Run()
        c.Assert(err, IsNil)
 
-       squeueUpdater.Done()
+       sqCheck.Stop()
 
        c.Check(sbatchCmdLine, DeepEquals, sbatchCmdComps)
 
@@ -193,7 +193,7 @@ func testWithServerStub(c *C, apiStubResponses map[string]arvadostest.StubRespon
        api := httptest.NewServer(&apiStub)
        defer api.Close()
 
-       arv := arvadosclient.ArvadosClient{
+       arv := &arvadosclient.ArvadosClient{
                Scheme:    "http",
                ApiServer: api.URL[7:],
                ApiToken:  "abc123",
@@ -205,12 +205,11 @@ func testWithServerStub(c *C, apiStubResponses map[string]arvadostest.StubRespon
        log.SetOutput(io.MultiWriter(buf, os.Stderr))
        defer log.SetOutput(os.Stderr)
 
-       config.CrunchRunCommand = []string{crunchCmd}
+       theConfig.CrunchRunCommand = []string{crunchCmd}
 
-       doneProcessing := make(chan struct{})
        dispatcher := dispatch.Dispatcher{
-               Arv:          arv,
-               PollInterval: time.Duration(1) * time.Second,
+               Arv:        arv,
+               PollPeriod: time.Duration(1) * time.Second,
                RunContainer: func(dispatcher *dispatch.Dispatcher,
                        container arvados.Container,
                        status chan arvados.Container) {
@@ -220,18 +219,18 @@ func testWithServerStub(c *C, apiStubResponses map[string]arvadostest.StubRespon
                                dispatcher.UpdateState(container.UUID, dispatch.Complete)
                        }()
                        run(dispatcher, container, status)
-                       doneProcessing <- struct{}{}
+                       dispatcher.Stop()
                },
-               DoneProcessing: doneProcessing}
+       }
 
        go func() {
                for i := 0; i < 80 && !strings.Contains(buf.String(), expected); i++ {
                        time.Sleep(100 * time.Millisecond)
                }
-               dispatcher.DoneProcessing <- struct{}{}
+               dispatcher.Stop()
        }()
 
-       err := dispatcher.RunDispatcher()
+       err := dispatcher.Run()
        c.Assert(err, IsNil)
 
        c.Check(buf.String(), Matches, `(?ms).*`+expected+`.*`)
@@ -303,15 +302,27 @@ func (s *MockArvadosServerSuite) TestSbatchFuncWithConfigArgs(c *C) {
 }
 
 func testSbatchFuncWithArgs(c *C, args []string) {
-       config.SbatchArguments = append(config.SbatchArguments, args...)
+       theConfig.SbatchArguments = append(theConfig.SbatchArguments, args...)
+
+       container := arvados.Container{UUID: "123", RuntimeConstraints: arvados.RuntimeConstraints{RAM: 250000000, VCPUs: 2}}
+       sbatchCmd := sbatchFunc(container)
+
+       var expected []string
+       expected = append(expected, "sbatch", "--share")
+       expected = append(expected, theConfig.SbatchArguments...)
+       expected = append(expected, "--job-name=123", "--mem-per-cpu=120", "--cpus-per-task=2")
+
+       c.Check(sbatchCmd.Args, DeepEquals, expected)
+}
 
-       container := arvados.Container{UUID: "123", RuntimeConstraints: arvados.RuntimeConstraints{RAM: 1000000, VCPUs: 2}}
+func (s *MockArvadosServerSuite) TestSbatchPartition(c *C) {
+       theConfig.SbatchArguments = nil
+       container := arvados.Container{UUID: "123", RuntimeConstraints: arvados.RuntimeConstraints{RAM: 250000000, VCPUs: 1}, SchedulingParameters: arvados.SchedulingParameters{Partitions: []string{"blurb", "b2"}}}
        sbatchCmd := sbatchFunc(container)
 
        var expected []string
        expected = append(expected, "sbatch", "--share")
-       expected = append(expected, config.SbatchArguments...)
-       expected = append(expected, "--job-name=123", "--mem-per-cpu=1", "--cpus-per-task=2")
+       expected = append(expected, "--job-name=123", "--mem-per-cpu=239", "--cpus-per-task=1", "--partition=blurb,b2")
 
        c.Check(sbatchCmd.Args, DeepEquals, expected)
 }