@@ -87,8 +87,18 @@ func (s *DockerSuite) TestApiNetworkStats(c *check.C) {
8787 contIP := findContainerIP (c , id )
8888 numPings := 10
8989
90+ var preRxPackets uint64
91+ var preTxPackets uint64
92+ var postRxPackets uint64
93+ var postTxPackets uint64
94+
9095 // Get the container networking stats before and after pinging the container
9196 nwStatsPre := getNetworkStats (c , id )
97+ for _ , v := range nwStatsPre {
98+ preRxPackets += v .RxPackets
99+ preTxPackets += v .TxPackets
100+ }
101+
92102 countParam := "-c"
93103 if runtime .GOOS == "windows" {
94104 countParam = "-n" // Ping count parameter is -n on Windows
@@ -97,18 +107,22 @@ func (s *DockerSuite) TestApiNetworkStats(c *check.C) {
97107 pingouts := string (pingout [:])
98108 c .Assert (err , check .IsNil )
99109 nwStatsPost := getNetworkStats (c , id )
110+ for _ , v := range nwStatsPost {
111+ postRxPackets += v .RxPackets
112+ postTxPackets += v .TxPackets
113+ }
100114
101115 // Verify the stats contain at least the expected number of packets (account for ARP)
102- expRxPkts := 1 + nwStatsPre . RxPackets + uint64 (numPings )
103- expTxPkts := 1 + nwStatsPre . TxPackets + uint64 (numPings )
104- c .Assert (nwStatsPost . TxPackets >= expTxPkts , check .Equals , true ,
105- check .Commentf ("Reported less TxPackets than expected. Expected >= %d. Found %d. %s" , expTxPkts , nwStatsPost . TxPackets , pingouts ))
106- c .Assert (nwStatsPost . RxPackets >= expRxPkts , check .Equals , true ,
107- check .Commentf ("Reported less Txbytes than expected. Expected >= %d. Found %d. %s" , expRxPkts , nwStatsPost . RxPackets , pingouts ))
116+ expRxPkts := 1 + preRxPackets + uint64 (numPings )
117+ expTxPkts := 1 + preTxPackets + uint64 (numPings )
118+ c .Assert (postTxPackets >= expTxPkts , check .Equals , true ,
119+ check .Commentf ("Reported less TxPackets than expected. Expected >= %d. Found %d. %s" , expTxPkts , postTxPackets , pingouts ))
120+ c .Assert (postRxPackets >= expRxPkts , check .Equals , true ,
121+ check .Commentf ("Reported less Txbytes than expected. Expected >= %d. Found %d. %s" , expRxPkts , postRxPackets , pingouts ))
108122}
109123
110- func getNetworkStats (c * check.C , id string ) types.NetworkStats {
111- var st * types.Stats
124+ func getNetworkStats (c * check.C , id string ) map [ string ] types.NetworkStats {
125+ var st * types.StatsJSON
112126
113127 _ , body , err := sockRequestRaw ("GET" , fmt .Sprintf ("/containers/%s/stats?stream=false" , id ), nil , "" )
114128 c .Assert (err , check .IsNil )
@@ -117,5 +131,5 @@ func getNetworkStats(c *check.C, id string) types.NetworkStats {
117131 c .Assert (err , check .IsNil )
118132 body .Close ()
119133
120- return st .Network
134+ return st .Networks
121135}
0 commit comments