Browse code

Make network stats version test concurrent

This change makes the test run go down from 10s to 2s

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Michael Crosby authored on 2016/08/04 05:24:55
Showing 1 changed files
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"runtime"
9 9
 	"strconv"
10 10
 	"strings"
11
+	"sync"
11 12
 	"time"
12 13
 
13 14
 	"github.com/docker/docker/pkg/integration/checker"
... ...
@@ -145,18 +146,24 @@ func (s *DockerSuite) TestApiStatsNetworkStatsVersioning(c *check.C) {
145 145
 	out, _ := runSleepingContainer(c)
146 146
 	id := strings.TrimSpace(out)
147 147
 	c.Assert(waitRun(id), checker.IsNil)
148
+	wg := sync.WaitGroup{}
148 149
 
149 150
 	for i := 17; i <= 21; i++ {
150
-		apiVersion := fmt.Sprintf("v1.%d", i)
151
-		statsJSONBlob := getVersionedStats(c, id, apiVersion)
152
-		if versions.LessThan(apiVersion, "v1.21") {
153
-			c.Assert(jsonBlobHasLTv121NetworkStats(statsJSONBlob), checker.Equals, true,
154
-				check.Commentf("Stats JSON blob from API %s %#v does not look like a <v1.21 API stats structure", apiVersion, statsJSONBlob))
155
-		} else {
156
-			c.Assert(jsonBlobHasGTE121NetworkStats(statsJSONBlob), checker.Equals, true,
157
-				check.Commentf("Stats JSON blob from API %s %#v does not look like a >=v1.21 API stats structure", apiVersion, statsJSONBlob))
158
-		}
151
+		wg.Add(1)
152
+		go func() {
153
+			defer wg.Done()
154
+			apiVersion := fmt.Sprintf("v1.%d", i)
155
+			statsJSONBlob := getVersionedStats(c, id, apiVersion)
156
+			if versions.LessThan(apiVersion, "v1.21") {
157
+				c.Assert(jsonBlobHasLTv121NetworkStats(statsJSONBlob), checker.Equals, true,
158
+					check.Commentf("Stats JSON blob from API %s %#v does not look like a <v1.21 API stats structure", apiVersion, statsJSONBlob))
159
+			} else {
160
+				c.Assert(jsonBlobHasGTE121NetworkStats(statsJSONBlob), checker.Equals, true,
161
+					check.Commentf("Stats JSON blob from API %s %#v does not look like a >=v1.21 API stats structure", apiVersion, statsJSONBlob))
162
+			}
163
+		}()
159 164
 	}
165
+	wg.Wait()
160 166
 }
161 167
 
162 168
 func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {