Skip to content

Commit

Permalink
Tests in progress
Browse files Browse the repository at this point in the history
Signed-off-by: John Howard <jhoward@microsoft.com>
  • Loading branch information
John Howard committed Aug 17, 2016
1 parent 8924d2f commit 51800fb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
20 changes: 5 additions & 15 deletions integration-cli/docker_api_containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,10 @@ func (s *DockerSuite) TestContainerApiGetChanges(c *check.C) {
}

func (s *DockerSuite) TestGetContainerStats(c *check.C) {
// Problematic on Windows as Windows does not support stats
testRequires(c, DaemonIsLinux)
var (
name = "statscontainer"
)
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
runSleepingContainer(c, "--name", name)

type b struct {
status int
Expand Down Expand Up @@ -208,9 +206,7 @@ func (s *DockerSuite) TestGetContainerStats(c *check.C) {
}

func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
// Problematic on Windows as Windows does not support stats
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
out, _ := runSleepingContainer(c)
id := strings.TrimSpace(out)

buf := &integration.ChannelBuffer{make(chan []byte, 1)}
Expand Down Expand Up @@ -245,10 +241,8 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
// previous test was just checking one stat entry so it didn't fail (stats with
// stream false always return one stat)
func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
// Problematic on Windows as Windows does not support stats
testRequires(c, DaemonIsLinux)
name := "statscontainer"
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
runSleepingContainer(c, "--name", name)

type b struct {
status int
Expand Down Expand Up @@ -283,10 +277,8 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
}

func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
// Problematic on Windows as Windows does not support stats
testRequires(c, DaemonIsLinux)
name := "statscontainer"
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
runSleepingContainer(c, "--name", name)

type b struct {
status int
Expand Down Expand Up @@ -319,10 +311,8 @@ func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
}

func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
// Problematic on Windows as Windows does not support stats
testRequires(c, DaemonIsLinux)
name := "statscontainer"
dockerCmd(c, "create", "--name", name, "busybox", "top")
dockerCmd(c, "create", "--name", name, "busybox", "ps")

type stats struct {
status int
Expand Down
33 changes: 25 additions & 8 deletions integration-cli/docker_api_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
var expectedNetworkInterfaceStats = strings.Split("rx_bytes rx_dropped rx_errors rx_packets tx_bytes tx_dropped tx_errors tx_packets", " ")

func (s *DockerSuite) TestApiStatsNoStreamGetCpu(c *check.C) {
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;do echo 'Hello'; usleep 100000; done")

id := strings.TrimSpace(out)
Expand All @@ -37,15 +36,30 @@ func (s *DockerSuite) TestApiStatsNoStreamGetCpu(c *check.C) {
body.Close()

var cpuPercent = 0.0
cpuDelta := float64(v.CPUStats.CPUUsage.TotalUsage - v.PreCPUStats.CPUUsage.TotalUsage)
systemDelta := float64(v.CPUStats.SystemUsage - v.PreCPUStats.SystemUsage)
cpuPercent = (cpuDelta / systemDelta) * float64(len(v.CPUStats.CPUUsage.PercpuUsage)) * 100.0

if daemonPlatform != "windows" {
cpuDelta := float64(v.CPUStats.CPUUsage.TotalUsage - v.PreCPUStats.CPUUsage.TotalUsage)
systemDelta := float64(v.CPUStats.SystemUsage - v.PreCPUStats.SystemUsage)
cpuPercent = (cpuDelta / systemDelta) * float64(len(v.CPUStats.CPUUsage.PercpuUsage)) * 100.0
} else {
// Max number of 100ns intervals between the previous time read and now
possIntervals := uint64(v.Read.Sub(v.PreRead).Nanoseconds()) // Start with number of ns intervals
possIntervals /= 100 // Convert to number of 100ns intervals
possIntervals *= uint64(v.NumProcs) // Multiple by the number of processors

// Intervals used
intervalsUsed := v.CPUStats.CPUUsage.TotalUsage - v.PreCPUStats.CPUUsage.TotalUsage

// Percentage avoiding divide-by-zero
if possIntervals > 0 {
cpuPercent = float64(intervalsUsed) / float64(possIntervals) * 100.0
}
}

c.Assert(cpuPercent, check.Not(checker.Equals), 0.0, check.Commentf("docker stats with no-stream get cpu usage failed: was %v", cpuPercent))
}

func (s *DockerSuite) TestApiStatsStoppedContainerInGoroutines(c *check.C) {
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo 1")
id := strings.TrimSpace(out)

Expand Down Expand Up @@ -82,14 +96,17 @@ func (s *DockerSuite) TestApiStatsStoppedContainerInGoroutines(c *check.C) {

func (s *DockerSuite) TestApiStatsNetworkStats(c *check.C) {
testRequires(c, SameHostDaemon)
testRequires(c, DaemonIsLinux)

out, _ := runSleepingContainer(c)
id := strings.TrimSpace(out)
c.Assert(waitRun(id), checker.IsNil)

// Retrieve the container address
contIP := findContainerIP(c, id, "bridge")
net := "bridge"
if daemonPlatform == "windows" {
net = "nat"
}
contIP := findContainerIP(c, id, net)
numPings := 1

var preRxPackets uint64
Expand Down Expand Up @@ -141,7 +158,7 @@ func (s *DockerSuite) TestApiStatsNetworkStats(c *check.C) {

func (s *DockerSuite) TestApiStatsNetworkStatsVersioning(c *check.C) {
testRequires(c, SameHostDaemon)
testRequires(c, DaemonIsLinux)
//testRequires(c, DaemonIsLinux)

out, _ := runSleepingContainer(c)
id := strings.TrimSpace(out)
Expand Down

0 comments on commit 51800fb

Please sign in to comment.