Fix potential race in ThrottledLogger flusher.
[arvados.git] / services / crunch-run / crunchrun_test.go
index 242e207fc990c3ace32f5bed2df5196ffc873621..644e9e9f586e788194bc45541e1665a0e5f6f1d4 100644 (file)
@@ -14,9 +14,9 @@ import (
        . "gopkg.in/check.v1"
        "io"
        "io/ioutil"
-       "log"
        "os"
        "os/exec"
+       "path/filepath"
        "sort"
        "strings"
        "sync"
@@ -132,37 +132,37 @@ func (*TestDockerClient) RemoveImage(name string, force bool) ([]*dockerclient.I
        return nil, nil
 }
 
-func (this *ArvTestClient) Create(resourceType string,
+func (client *ArvTestClient) Create(resourceType string,
        parameters arvadosclient.Dict,
        output interface{}) error {
 
-       this.Mutex.Lock()
-       defer this.Mutex.Unlock()
+       client.Mutex.Lock()
+       defer client.Mutex.Unlock()
 
-       this.Calls += 1
-       this.Content = append(this.Content, parameters)
+       client.Calls++
+       client.Content = append(client.Content, parameters)
 
        if resourceType == "logs" {
                et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
-               if this.Logs == nil {
-                       this.Logs = make(map[string]*bytes.Buffer)
+               if client.Logs == nil {
+                       client.Logs = make(map[string]*bytes.Buffer)
                }
-               if this.Logs[et] == nil {
-                       this.Logs[et] = &bytes.Buffer{}
+               if client.Logs[et] == nil {
+                       client.Logs[et] = &bytes.Buffer{}
                }
-               this.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
+               client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
        }
 
        if resourceType == "collections" && output != nil {
                mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
-               outmap := output.(*CollectionRecord)
+               outmap := output.(*arvados.Collection)
                outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
        }
 
        return nil
 }
 
-func (this *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
+func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
        switch {
        case method == "GET" && resourceType == "containers" && action == "auth":
                return json.Unmarshal([]byte(`{
@@ -175,28 +175,28 @@ func (this *ArvTestClient) Call(method, resourceType, uuid, action string, param
        }
 }
 
-func (this *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
+func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
        if resourceType == "collections" {
                if uuid == hwPDH {
-                       output.(*CollectionRecord).ManifestText = hwManifest
+                       output.(*arvados.Collection).ManifestText = hwManifest
                } else if uuid == otherPDH {
-                       output.(*CollectionRecord).ManifestText = otherManifest
+                       output.(*arvados.Collection).ManifestText = otherManifest
                }
        }
        if resourceType == "containers" {
-               (*output.(*arvados.Container)) = this.Container
+               (*output.(*arvados.Container)) = client.Container
        }
        return nil
 }
 
-func (this *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
-       this.Mutex.Lock()
-       defer this.Mutex.Unlock()
-       this.Calls += 1
-       this.Content = append(this.Content, parameters)
+func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
+       client.Mutex.Lock()
+       defer client.Mutex.Unlock()
+       client.Calls++
+       client.Content = append(client.Content, parameters)
        if resourceType == "containers" {
                if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
-                       this.WasSetRunning = true
+                       client.WasSetRunning = true
                }
        }
        return nil
@@ -206,9 +206,9 @@ func (this *ArvTestClient) Update(resourceType string, uuid string, parameters a
 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
 // no call matches, it returns nil.
-func (this *ArvTestClient) CalledWith(jpath, expect string) arvadosclient.Dict {
+func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
 call:
-       for _, content := range this.Content {
+       for _, content := range client.Content {
                var v interface{} = content
                for _, k := range strings.Split(jpath, ".") {
                        if dict, ok := v.(arvadosclient.Dict); !ok {
@@ -217,15 +217,15 @@ call:
                                v = dict[k]
                        }
                }
-               if v, ok := v.(string); ok && v == expect {
+               if v == expect {
                        return content
                }
        }
        return nil
 }
 
-func (this *KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
-       this.Content = buf
+func (client *KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
+       client.Content = buf
        return fmt.Sprintf("%s+%d", hash, len(buf)), len(buf), nil
 }
 
@@ -234,14 +234,14 @@ type FileWrapper struct {
        len uint64
 }
 
-func (this FileWrapper) Len() uint64 {
-       return this.len
+func (fw FileWrapper) Len() uint64 {
+       return fw.len
 }
 
-func (this *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error) {
+func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error) {
        if filename == hwImageId+".tar" {
                rdr := ioutil.NopCloser(&bytes.Buffer{})
-               this.Called = true
+               client.Called = true
                return FileWrapper{rdr, 1321984}, nil
        }
        return nil, nil
@@ -288,54 +288,56 @@ func (s *TestSuite) TestLoadImage(c *C) {
 }
 
 type ArvErrorTestClient struct{}
-type KeepErrorTestClient struct{}
-type KeepReadErrorTestClient struct{}
 
-func (this ArvErrorTestClient) Create(resourceType string,
+func (ArvErrorTestClient) Create(resourceType string,
        parameters arvadosclient.Dict,
        output interface{}) error {
        return nil
 }
 
-func (this ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
+func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
        return errors.New("ArvError")
 }
 
-func (this ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
+func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
        return errors.New("ArvError")
 }
 
-func (this ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
+func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
        return nil
 }
 
-func (this KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
+type KeepErrorTestClient struct{}
+
+func (KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
        return "", 0, errors.New("KeepError")
 }
 
-func (this KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error) {
+func (KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error) {
        return nil, errors.New("KeepError")
 }
 
-func (this KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
+type KeepReadErrorTestClient struct{}
+
+func (KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
        return "", 0, nil
 }
 
 type ErrorReader struct{}
 
-func (this ErrorReader) Read(p []byte) (n int, err error) {
+func (ErrorReader) Read(p []byte) (n int, err error) {
        return 0, errors.New("ErrorReader")
 }
 
-func (this ErrorReader) Close() error {
+func (ErrorReader) Close() error {
        return nil
 }
 
-func (this ErrorReader) Len() uint64 {
+func (ErrorReader) Len() uint64 {
        return 0
 }
 
-func (this KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error) {
+func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error) {
        return ErrorReader{}, nil
 }
 
@@ -381,21 +383,21 @@ type ClosableBuffer struct {
        bytes.Buffer
 }
 
+func (*ClosableBuffer) Close() error {
+       return nil
+}
+
 type TestLogs struct {
        Stdout ClosableBuffer
        Stderr ClosableBuffer
 }
 
-func (this *ClosableBuffer) Close() error {
-       return nil
-}
-
-func (this *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
+func (tl *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
        if logstr == "stdout" {
-               return &this.Stdout
+               return &tl.Stdout
        }
        if logstr == "stderr" {
-               return &this.Stderr
+               return &tl.Stderr
        }
        return nil
 }
@@ -516,6 +518,7 @@ func FullRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvT
 
        api = &ArvTestClient{Container: rec}
        cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
+       cr.statInterval = 100 * time.Millisecond
        am := &ArvMountCmdLine{}
        cr.RunArvMount = am.ArvMountTest
 
@@ -551,14 +554,45 @@ func (s *TestSuite) TestFullRunHello(c *C) {
                t.finish <- dockerclient.WaitResult{}
        })
 
-       c.Check(api.Calls, Equals, 7)
-       c.Check(api.Content[6]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
-       c.Check(api.Content[6]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
-
+       c.Check(api.CalledWith("container.exit_code", 0), NotNil)
+       c.Check(api.CalledWith("container.state", "Complete"), NotNil)
        c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
 
 }
 
+func (s *TestSuite) TestCrunchstat(c *C) {
+       api, _ := FullRunHelper(c, `{
+               "command": ["sleep", "1"],
+               "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
+               "cwd": ".",
+               "environment": {},
+               "mounts": {"/tmp": {"kind": "tmp"} },
+               "output_path": "/tmp",
+               "priority": 1,
+               "runtime_constraints": {}
+       }`, func(t *TestDockerClient) {
+               time.Sleep(time.Second)
+               t.logWriter.Close()
+               t.finish <- dockerclient.WaitResult{}
+       })
+
+       c.Check(api.CalledWith("container.exit_code", 0), NotNil)
+       c.Check(api.CalledWith("container.state", "Complete"), NotNil)
+
+       // We didn't actually start a container, so crunchstat didn't
+       // find accounting files and therefore didn't log any stats.
+       // It should have logged a "can't find accounting files"
+       // message after one poll interval, though, so we can confirm
+       // it's alive:
+       c.Assert(api.Logs["crunchstat"], NotNil)
+       c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
+
+       // The "files never appeared" log assures us that we called
+       // (*crunchstat.Reporter)Stop(), and that we set it up with
+       // the correct container ID "abcde":
+       c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for abcde\n`)
+}
+
 func (s *TestSuite) TestFullRunStderr(c *C) {
        api, _ := FullRunHelper(c, `{
     "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
@@ -576,10 +610,10 @@ func (s *TestSuite) TestFullRunStderr(c *C) {
                t.finish <- dockerclient.WaitResult{ExitCode: 1}
        })
 
-       c.Assert(api.Calls, Equals, 8)
-       c.Check(api.Content[7]["container"].(arvadosclient.Dict)["log"], NotNil)
-       c.Check(api.Content[7]["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
-       c.Check(api.Content[7]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
+       final := api.CalledWith("container.state", "Complete")
+       c.Assert(final, NotNil)
+       c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
+       c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
 
        c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
        c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
@@ -601,12 +635,9 @@ func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
                t.finish <- dockerclient.WaitResult{ExitCode: 0}
        })
 
-       c.Check(api.Calls, Equals, 7)
-       c.Check(api.Content[6]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
-       c.Check(api.Content[6]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
-
-       log.Print(api.Logs["stdout"].String())
-
+       c.Check(api.CalledWith("container.exit_code", 0), NotNil)
+       c.Check(api.CalledWith("container.state", "Complete"), NotNil)
+       c.Log(api.Logs["stdout"])
        c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
 }
 
@@ -626,10 +657,8 @@ func (s *TestSuite) TestFullRunSetCwd(c *C) {
                t.finish <- dockerclient.WaitResult{ExitCode: 0}
        })
 
-       c.Check(api.Calls, Equals, 7)
-       c.Check(api.Content[6]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
-       c.Check(api.Content[6]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
-
+       c.Check(api.CalledWith("container.exit_code", 0), NotNil)
+       c.Check(api.CalledWith("container.state", "Complete"), NotNil)
        c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/bin\n"), Equals, true)
 }
 
@@ -680,9 +709,8 @@ func (s *TestSuite) TestCancel(c *C) {
                }
        }
 
-       c.Assert(api.Calls, Equals, 6)
-       c.Check(api.Content[5]["container"].(arvadosclient.Dict)["log"], IsNil)
-       c.Check(api.Content[5]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
+       c.Check(api.CalledWith("container.log", nil), NotNil)
+       c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
        c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "foo\n"), Equals, true)
 
 }
@@ -703,10 +731,8 @@ func (s *TestSuite) TestFullRunSetEnv(c *C) {
                t.finish <- dockerclient.WaitResult{ExitCode: 0}
        })
 
-       c.Check(api.Calls, Equals, 7)
-       c.Check(api.Content[6]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
-       c.Check(api.Content[6]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
-
+       c.Check(api.CalledWith("container.exit_code", 0), NotNil)
+       c.Check(api.CalledWith("container.state", "Complete"), NotNil)
        c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
 }
 
@@ -728,73 +754,117 @@ func (s *TestSuite) TestSetupMounts(c *C) {
        am := &ArvMountCmdLine{}
        cr.RunArvMount = am.ArvMountTest
 
+       realTemp, err := ioutil.TempDir("", "crunchrun_test-")
+       c.Assert(err, IsNil)
+       defer os.RemoveAll(realTemp)
+
        i := 0
-       cr.MkTempDir = func(string, string) (string, error) {
-               i += 1
-               d := fmt.Sprintf("/tmp/mktmpdir%d", i)
-               os.Mkdir(d, os.ModePerm)
-               return d, nil
+       cr.MkTempDir = func(_ string, prefix string) (string, error) {
+               i++
+               d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
+               err := os.Mkdir(d, os.ModePerm)
+               if err != nil && strings.Contains(err.Error(), ": file exists") {
+                       // Test case must have pre-populated the tempdir
+                       err = nil
+               }
+               return d, err
+       }
+
+       checkEmpty := func() {
+               filepath.Walk(realTemp, func(path string, _ os.FileInfo, err error) error {
+                       c.Check(path, Equals, realTemp)
+                       c.Check(err, IsNil)
+                       return nil
+               })
        }
 
        {
+               i = 0
                cr.Container.Mounts = make(map[string]arvados.Mount)
                cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
                cr.OutputPath = "/tmp"
 
                err := cr.SetupMounts()
                c.Check(err, IsNil)
-               c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", "/tmp/mktmpdir1"})
-               c.Check(cr.Binds, DeepEquals, []string{"/tmp/mktmpdir2:/tmp"})
+               c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
+               c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp"})
                cr.CleanupDirs()
+               checkEmpty()
        }
 
        {
                i = 0
-               cr.Container.Mounts = make(map[string]arvados.Mount)
-               cr.Container.Mounts["/keeptmp"] = arvados.Mount{Kind: "collection", Writable: true}
+               cr.Container.Mounts = map[string]arvados.Mount{
+                       "/keeptmp": {Kind: "collection", Writable: true},
+               }
                cr.OutputPath = "/keeptmp"
 
-               os.MkdirAll("/tmp/mktmpdir1/tmp0", os.ModePerm)
+               os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
 
                err := cr.SetupMounts()
                c.Check(err, IsNil)
-               c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "/tmp/mktmpdir1"})
-               c.Check(cr.Binds, DeepEquals, []string{"/tmp/mktmpdir1/tmp0:/keeptmp"})
+               c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
+               c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/tmp0:/keeptmp"})
                cr.CleanupDirs()
+               checkEmpty()
        }
 
        {
                i = 0
-               cr.Container.Mounts = make(map[string]arvados.Mount)
-               cr.Container.Mounts["/keepinp"] = arvados.Mount{Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"}
-               cr.Container.Mounts["/keepout"] = arvados.Mount{Kind: "collection", Writable: true}
+               cr.Container.Mounts = map[string]arvados.Mount{
+                       "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
+                       "/keepout": {Kind: "collection", Writable: true},
+               }
                cr.OutputPath = "/keepout"
 
-               os.MkdirAll("/tmp/mktmpdir1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
-               os.MkdirAll("/tmp/mktmpdir1/tmp0", os.ModePerm)
+               os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
+               os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
+
+               err := cr.SetupMounts()
+               c.Check(err, IsNil)
+               c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
+               sort.StringSlice(cr.Binds).Sort()
+               c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
+                       realTemp + "/keep1/tmp0:/keepout"})
+               cr.CleanupDirs()
+               checkEmpty()
+       }
 
+       for _, test := range []struct {
+               in  interface{}
+               out string
+       }{
+               {in: "foo", out: `"foo"`},
+               {in: nil, out: `null`},
+               {in: map[string]int{"foo": 123}, out: `{"foo":123}`},
+       } {
+               i = 0
+               cr.Container.Mounts = map[string]arvados.Mount{
+                       "/mnt/test.json": {Kind: "json", Content: test.in},
+               }
                err := cr.SetupMounts()
                c.Check(err, IsNil)
-               c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "/tmp/mktmpdir1"})
-               var ss sort.StringSlice = cr.Binds
-               ss.Sort()
-               c.Check(cr.Binds, DeepEquals, []string{"/tmp/mktmpdir1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
-                       "/tmp/mktmpdir1/tmp0:/keepout"})
+               sort.StringSlice(cr.Binds).Sort()
+               c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2/mountdata.json:/mnt/test.json:ro"})
+               content, err := ioutil.ReadFile(realTemp + "/2/mountdata.json")
+               c.Check(err, IsNil)
+               c.Check(content, DeepEquals, []byte(test.out))
                cr.CleanupDirs()
+               checkEmpty()
        }
 }
 
 func (s *TestSuite) TestStdout(c *C) {
-       helperRecord := `{`
-       helperRecord += `"command": ["/bin/sh", "-c", "echo $FROBIZ"],`
-       helperRecord += `"container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",`
-       helperRecord += `"cwd": "/bin",`
-       helperRecord += `"environment": {"FROBIZ": "bilbo"},`
-       helperRecord += `"mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },`
-       helperRecord += `"output_path": "/tmp",`
-       helperRecord += `"priority": 1,`
-       helperRecord += `"runtime_constraints": {}`
-       helperRecord += `}`
+       helperRecord := `{
+               "command": ["/bin/sh", "-c", "echo $FROBIZ"],
+               "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
+               "cwd": "/bin",
+               "environment": {"FROBIZ": "bilbo"},
+               "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
+               "output_path": "/tmp",
+               "priority": 1,
+               "runtime_constraints": {}
+       }`
 
        api, _ := FullRunHelper(c, helperRecord, func(t *TestDockerClient) {
                t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
@@ -802,10 +872,9 @@ func (s *TestSuite) TestStdout(c *C) {
                t.finish <- dockerclient.WaitResult{ExitCode: 0}
        })
 
-       c.Assert(api.Calls, Equals, 6)
-       c.Check(api.Content[5]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
-       c.Check(api.Content[5]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
-       c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), Not(IsNil))
+       c.Check(api.CalledWith("container.exit_code", 0), NotNil)
+       c.Check(api.CalledWith("container.state", "Complete"), NotNil)
+       c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
 }
 
 // Used by the TestStdoutWithWrongPath*()