2015-02-13 19:45:04 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-09-17 00:16:55 +03:00
|
|
|
"bytes"
|
2015-02-13 19:45:04 +03:00
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestCliStatsNoStream(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
2015-02-13 19:45:04 +03:00
|
|
|
id := strings.TrimSpace(out)
|
2015-08-11 10:41:11 +03:00
|
|
|
c.Assert(waitRun(id), check.IsNil)
|
2015-02-13 19:45:04 +03:00
|
|
|
|
|
|
|
statsCmd := exec.Command(dockerBinary, "stats", "--no-stream", id)
|
2015-09-17 00:16:55 +03:00
|
|
|
type output struct {
|
|
|
|
out []byte
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
ch := make(chan output)
|
2015-02-13 19:45:04 +03:00
|
|
|
go func() {
|
2015-09-17 00:16:55 +03:00
|
|
|
out, err := statsCmd.Output()
|
|
|
|
ch <- output{out, err}
|
2015-02-13 19:45:04 +03:00
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
2015-09-17 00:16:55 +03:00
|
|
|
case outerr := <-ch:
|
|
|
|
if outerr.err != nil {
|
|
|
|
c.Fatalf("Error running stats: %v", outerr.err)
|
|
|
|
}
|
|
|
|
if !bytes.Contains(outerr.out, []byte(id)) {
|
|
|
|
c.Fatalf("running container wasn't present in output")
|
2015-02-13 19:45:04 +03:00
|
|
|
}
|
2015-05-30 20:25:51 +03:00
|
|
|
case <-time.After(3 * time.Second):
|
2015-02-13 19:45:04 +03:00
|
|
|
statsCmd.Process.Kill()
|
|
|
|
c.Fatalf("stats did not return immediately when not streaming")
|
|
|
|
}
|
2015-09-17 00:16:55 +03:00
|
|
|
|
2015-02-13 19:45:04 +03:00
|
|
|
}
|