github.com/SophiaGitHub/hello@v1.7.1-rc3/integration-cli/docker_cli_stats_test.go (about) 1 package main 2 3 import ( 4 "os/exec" 5 "strings" 6 "time" 7 8 "github.com/go-check/check" 9 ) 10 11 func (s *DockerSuite) TestCliStatsNoStream(c *check.C) { 12 out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "busybox", "top")) 13 if err != nil { 14 c.Fatalf("Error on container creation: %v, output: %s", err, out) 15 } 16 id := strings.TrimSpace(out) 17 if err := waitRun(id); err != nil { 18 c.Fatalf("error waiting for container to start: %v", err) 19 } 20 21 statsCmd := exec.Command(dockerBinary, "stats", "--no-stream", id) 22 chErr := make(chan error) 23 go func() { 24 chErr <- statsCmd.Run() 25 }() 26 27 select { 28 case err := <-chErr: 29 if err != nil { 30 c.Fatalf("Error running stats: %v", err) 31 } 32 case <-time.After(3 * time.Second): 33 statsCmd.Process.Kill() 34 c.Fatalf("stats did not return immediately when not streaming") 35 } 36 }