Skip to content

Commit abe50e7

Browse files
author
Peng Yin
committed
Fix test after enabled metrics on windows
1 parent 7154c59 commit abe50e7

7 files changed

+51
-111
lines changed

agent/app/agent_windows_test.go

-83
This file was deleted.

agent/config/config_windows_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestConfigDefault(t *testing.T) {
3434

3535
assert.Equal(t, "npipe:////./pipe/docker_engine", cfg.DockerEndpoint, "Default docker endpoint set incorrectly")
3636
assert.Equal(t, `C:\ProgramData\Amazon\ECS\data`, cfg.DataDir, "Default datadir set incorrectly")
37-
assert.True(t, cfg.DisableMetrics, "Default disablemetrics set incorrectly")
37+
assert.False(t, cfg.DisableMetrics, "Default disablemetrics set incorrectly")
3838
assert.Equal(t, 10, len(cfg.ReservedPorts), "Default reserved ports set incorrectly")
3939
assert.Equal(t, uint16(0), cfg.ReservedMemory, "Default reserved memory set incorrectly")
4040
assert.Equal(t, 30*time.Second, cfg.DockerStopTimeout, "Default docker stop container timeout set incorrectly")

agent/stats/container_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ func TestContainerStatsCollection(t *testing.T) {
6161
// deal with the docker.Stats.MemoryStats inner struct
6262
jsonStat := fmt.Sprintf(`
6363
{
64-
"memory_stats": {"usage":%d},
64+
"memory_stats": {"usage":%d, "privateworkingset":%d},
6565
"cpu_stats":{
6666
"cpu_usage":{
6767
"percpu_usage":[%d],
6868
"total_usage":%d
6969
}
7070
}
71-
}`, stat.memBytes, stat.cpuTime, stat.cpuTime)
71+
}`, stat.memBytes, stat.memBytes, stat.cpuTime, stat.cpuTime)
7272
dockerStat := &docker.Stats{}
7373
json.Unmarshal([]byte(jsonStat), dockerStat)
7474
dockerStat.Read = stat.timestamp

agent/stats/utils_test.go

+3-21
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,6 @@ func TestDockerStatsToContainerStatsCpuUsage(t *testing.T) {
6666
}
6767
}
6868

69-
func TestDockerStatsToContainerStatsZeroCoresGeneratesError(t *testing.T) {
70-
// doing this with json makes me sad, but is the easiest way to deal with
71-
// the inner structs
72-
jsonStat := fmt.Sprintf(`
73-
{
74-
"cpu_stats":{
75-
"cpu_usage":{
76-
"total_usage":%d
77-
}
78-
}
79-
}`, 100)
80-
dockerStat := &docker.Stats{}
81-
json.Unmarshal([]byte(jsonStat), dockerStat)
82-
_, err := dockerStatsToContainerStats(dockerStat)
83-
if err == nil {
84-
t.Error("Expected error converting container stats with empty PercpuUsage")
85-
}
86-
}
87-
8869
func TestDockerStatsToContainerStatsMemUsage(t *testing.T) {
8970
jsonStat := fmt.Sprintf(`
9071
{
@@ -100,9 +81,10 @@ func TestDockerStatsToContainerStatsMemUsage(t *testing.T) {
10081
"stats": {
10182
"cache": %d,
10283
"rss": %d
103-
}
84+
},
85+
"privateworkingset": %d
10486
}
105-
}`, 1, 2, 3, 4, 100, 30, 100, 20, 10)
87+
}`, 1, 2, 3, 4, 100, 30, 100, 20, 10, 10)
10688
dockerStat := &docker.Stats{}
10789
json.Unmarshal([]byte(jsonStat), dockerStat)
10890
containerStats, err := dockerStatsToContainerStats(dockerStat)

agent/stats/utils_unix.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525
func dockerStatsToContainerStats(dockerStats *docker.Stats) (*ContainerStats, error) {
2626
// The length of PercpuUsage represents the number of cores in an instance.
2727
if len(dockerStats.CPUStats.CPUUsage.PercpuUsage) == 0 {
28-
seelog.Debug("Invalid container statistics reported, invalid stats payload from docker")
29-
return nil, fmt.Errorf("Invalid container statistics reported")
28+
seelog.Debug("Invalid container statistics reported, no cpu core usage reported")
29+
return nil, fmt.Errorf("Invalid container statistics reported, no cpu core usage reported")
3030
}
3131

3232
cpuUsage := dockerStats.CPUStats.CPUUsage.TotalUsage / numCores

agent/stats/utils_unix_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// +build !windows
2+
// Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
5+
// not use this file except in compliance with the License. A copy of the
6+
// License is located at
7+
//
8+
// http://aws.amazon.com/apache2.0/
9+
//
10+
// or in the "license" file accompanying this file. This file is distributed
11+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
// express or implied. See the License for the specific language governing
13+
// permissions and limitations under the License.
14+
package stats
15+
16+
import (
17+
"encoding/json"
18+
"fmt"
19+
"testing"
20+
21+
docker "github.com/fsouza/go-dockerclient"
22+
)
23+
24+
func TestDockerStatsToContainerStatsZeroCoresGeneratesError(t *testing.T) {
25+
// doing this with json makes me sad, but is the easiest way to deal with
26+
// the inner structs
27+
jsonStat := fmt.Sprintf(`
28+
{
29+
"cpu_stats":{
30+
"cpu_usage":{
31+
"total_usage":%d
32+
}
33+
}
34+
}`, 100)
35+
dockerStat := &docker.Stats{}
36+
json.Unmarshal([]byte(jsonStat), dockerStat)
37+
_, err := dockerStatsToContainerStats(dockerStat)
38+
if err == nil {
39+
t.Error("Expected error converting container stats with empty PercpuUsage")
40+
}
41+
}

agent/stats/utils_windows.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
// dockerStatsToContainerStats returns a new object of the ContainerStats object from docker stats.
2525
func dockerStatsToContainerStats(dockerStats *docker.Stats) (*ContainerStats, error) {
2626
if numCores == uint64(0) {
27-
seelog.Error("Invalid number of cpu cores")
28-
return nil, fmt.Errorf("Invalid number of cpu cores")
27+
seelog.Error("Invalid number of cpu cores acquired from the system")
28+
return nil, fmt.Errorf("invalid number of cpu cores acquired from the system")
2929
}
3030

3131
cpuUsage := dockerStats.CPUStats.CPUUsage.TotalUsage / numCores

0 commit comments

Comments
 (0)