Merge branch '10690-config-dump'
[arvados.git] / services / crunch-dispatch-slurm / crunch-dispatch-slurm_test.go
index a55929838bc39cd86c27664ccee27c544b6b5cba..40461031e214486f1dbed9feeda6aae0d97fb76c 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,8 +144,7 @@ func (s *TestSuite) integrationTest(c *C,
        c.Check(err, IsNil)
        c.Check(len(containers.Items), Equals, 1)
 
-       echo := "echo"
-       config.CrunchRunCommand = &echo
+       theConfig.CrunchRunCommand = []string{"echo"}
 
        doneProcessing := make(chan struct{})
        dispatcher := dispatch.Dispatcher{
@@ -194,7 +194,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",
@@ -206,7 +206,7 @@ func testWithServerStub(c *C, apiStubResponses map[string]arvadostest.StubRespon
        log.SetOutput(io.MultiWriter(buf, os.Stderr))
        defer log.SetOutput(os.Stderr)
 
-       config.CrunchRunCommand = &crunchCmd
+       theConfig.CrunchRunCommand = []string{crunchCmd}
 
        doneProcessing := make(chan struct{})
        dispatcher := dispatch.Dispatcher{
@@ -304,15 +304,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)
 }