From 769df832a39e2507fb46cb8896666a1c3197ff0b Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Fri, 8 May 2015 08:28:50 -0700 Subject: [PATCH] Fix random errors in DockerSuite.TestNetworkNat I believe this was failing because 'nc' wouldn't show the data it received sometimes. So intead of looking for that data we now look for the output of the echo that comes after the nc command successfully runs Signed-off-by: Doug Davis --- integration-cli/docker_cli_nat_test.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/integration-cli/docker_cli_nat_test.go b/integration-cli/docker_cli_nat_test.go index 14237042ac..9e99d5716f 100644 --- a/integration-cli/docker_cli_nat_test.go +++ b/integration-cli/docker_cli_nat_test.go @@ -4,14 +4,15 @@ import ( "fmt" "net" "os/exec" - "strconv" "strings" "github.com/go-check/check" ) func startServerContainer(c *check.C, proto string, port int) string { - cmd := []string{"-d", "-p", fmt.Sprintf("%d:%d", port, port), "busybox", "nc", "-lp", strconv.Itoa(port)} + pStr := fmt.Sprintf("%d:%d", port, port) + bCmd := fmt.Sprintf("nc -lp %d && echo bye", port) + cmd := []string{"-d", "-p", pStr, "busybox", "sh", "-c", bCmd} if proto == "udp" { cmd = append(cmd, "-u") } @@ -75,7 +76,13 @@ func (s *DockerSuite) TestNetworkNat(c *check.C) { } result := getContainerLogs(c, srv) - if expected := "hello world"; result != expected { + + // Ideally we'd like to check for "hello world" but sometimes + // nc doesn't show the data it received so instead let's look for + // the output of the 'echo bye' that should be printed once + // the nc command gets a connection + expected := "bye" + if !strings.Contains(result, expected) { c.Fatalf("Unexpected output. Expected: %q, received: %q", expected, result) } } @@ -97,7 +104,13 @@ func (s *DockerSuite) TestNetworkLocalhostTCPNat(c *check.C) { conn.Close() result := getContainerLogs(c, srv) - if expected := "hello world"; result != expected { + + // Ideally we'd like to check for "hello world" but sometimes + // nc doesn't show the data it received so instead let's look for + // the output of the 'echo bye' that should be printed once + // the nc command gets a connection + expected := "bye" + if !strings.Contains(result, expected) { c.Fatalf("Unexpected output. Expected: %q, received: %q", expected, result) } }