Browse code

Make sure the container is well started prior to perform the test

Guillaume J. Charmes authored on 2013/04/24 02:28:40
Showing 1 changed files
... ...
@@ -273,7 +273,16 @@ func TestAllocatePortLocalhost(t *testing.T) {
273 273
 		t.Fatal(err)
274 274
 	}
275 275
 	defer container.Kill()
276
-	time.Sleep(600 * time.Millisecond) // Wait for the container to run
276
+
277
+	setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() {
278
+		for {
279
+			if container.State.Running {
280
+				break
281
+			}
282
+			time.Sleep(10 * time.Millisecond)
283
+		}
284
+	})
285
+
277 286
 	conn, err := net.Dial("tcp",
278 287
 		fmt.Sprintf(
279 288
 			"localhost:%s", container.NetworkSettings.PortMapping["5555"],
... ...
@@ -293,6 +302,7 @@ func TestAllocatePortLocalhost(t *testing.T) {
293 293
 			string(output),
294 294
 		)
295 295
 	}
296
+	container.Wait()
296 297
 }
297 298
 
298 299
 func TestRestore(t *testing.T) {