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 <dug@us.ibm.com>
| ... | ... |
@@ -4,14 +4,15 @@ import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
"net" |
| 6 | 6 |
"os/exec" |
| 7 |
- "strconv" |
|
| 8 | 7 |
"strings" |
| 9 | 8 |
|
| 10 | 9 |
"github.com/go-check/check" |
| 11 | 10 |
) |
| 12 | 11 |
|
| 13 | 12 |
func startServerContainer(c *check.C, proto string, port int) string {
|
| 14 |
- cmd := []string{"-d", "-p", fmt.Sprintf("%d:%d", port, port), "busybox", "nc", "-lp", strconv.Itoa(port)}
|
|
| 13 |
+ pStr := fmt.Sprintf("%d:%d", port, port)
|
|
| 14 |
+ bCmd := fmt.Sprintf("nc -lp %d && echo bye", port)
|
|
| 15 |
+ cmd := []string{"-d", "-p", pStr, "busybox", "sh", "-c", bCmd}
|
|
| 15 | 16 |
if proto == "udp" {
|
| 16 | 17 |
cmd = append(cmd, "-u") |
| 17 | 18 |
} |
| ... | ... |
@@ -75,7 +76,13 @@ func (s *DockerSuite) TestNetworkNat(c *check.C) {
|
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 | 77 |
result := getContainerLogs(c, srv) |
| 78 |
- if expected := "hello world"; result != expected {
|
|
| 78 |
+ |
|
| 79 |
+ // Ideally we'd like to check for "hello world" but sometimes |
|
| 80 |
+ // nc doesn't show the data it received so instead let's look for |
|
| 81 |
+ // the output of the 'echo bye' that should be printed once |
|
| 82 |
+ // the nc command gets a connection |
|
| 83 |
+ expected := "bye" |
|
| 84 |
+ if !strings.Contains(result, expected) {
|
|
| 79 | 85 |
c.Fatalf("Unexpected output. Expected: %q, received: %q", expected, result)
|
| 80 | 86 |
} |
| 81 | 87 |
} |
| ... | ... |
@@ -97,7 +104,13 @@ func (s *DockerSuite) TestNetworkLocalhostTCPNat(c *check.C) {
|
| 97 | 97 |
conn.Close() |
| 98 | 98 |
|
| 99 | 99 |
result := getContainerLogs(c, srv) |
| 100 |
- if expected := "hello world"; result != expected {
|
|
| 100 |
+ |
|
| 101 |
+ // Ideally we'd like to check for "hello world" but sometimes |
|
| 102 |
+ // nc doesn't show the data it received so instead let's look for |
|
| 103 |
+ // the output of the 'echo bye' that should be printed once |
|
| 104 |
+ // the nc command gets a connection |
|
| 105 |
+ expected := "bye" |
|
| 106 |
+ if !strings.Contains(result, expected) {
|
|
| 101 | 107 |
c.Fatalf("Unexpected output. Expected: %q, received: %q", expected, result)
|
| 102 | 108 |
} |
| 103 | 109 |
} |