1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration-cli/docker_cli_stats_test.go
Brian Goff f3023a93d1 Allow pulling stats once and disconnecting.
Adds a `stream` query param to the stats API which allows API users to
only collect one stats entry and disconnect instead of keeping the
connection alive to stream more stats.

Also adds a `--no-stream` flag to `docker stats` which does the same

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2015-05-04 10:49:13 -04:00

36 lines
830 B
Go

package main
import (
"os/exec"
"strings"
"time"
"github.com/go-check/check"
)
func (s *DockerSuite) TestCliStatsNoStream(c *check.C) {
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "busybox", "top"))
if err != nil {
c.Fatalf("Error on container creation: %v, output: %s", err, out)
}
id := strings.TrimSpace(out)
if err := waitRun(id); err != nil {
c.Fatalf("error waiting for container to start: %v", err)
}
statsCmd := exec.Command(dockerBinary, "stats", "--no-stream", id)
chErr := make(chan error)
go func() {
chErr <- statsCmd.Run()
}()
select {
case err := <-chErr:
if err != nil {
c.Fatalf("Error running stats: %v", err)
}
case <-time.After(2 * time.Second):
statsCmd.Process.Kill()
c.Fatalf("stats did not return immediately when not streaming")
}
}