Browse Source

Add Test for port allocation bug (port already in use by other programs than docker)

Signed-off-by: Tibor Vass <teabee89@gmail.com>
Tibor Vass 11 years ago
parent
commit
3109fc9537
1 changed files with 19 additions and 0 deletions
  1. 19 0
      integration-cli/docker_cli_run_test.go

+ 19 - 0
integration-cli/docker_cli_run_test.go

@@ -4,6 +4,7 @@ import (
 	"bufio"
 	"fmt"
 	"io/ioutil"
+	"net"
 	"os"
 	"os/exec"
 	"path"
@@ -1875,3 +1876,21 @@ func TestRunDeallocatePortOnMissingIptablesRule(t *testing.T) {
 	deleteAllContainers()
 	logDone("run - port should be deallocated even on iptables error")
 }
+
+func TestRunPortInUse(t *testing.T) {
+	port := "1234"
+	l, err := net.Listen("tcp", ":"+port)
+	if err != nil {
+		t.Fatal(err)
+	}
+	defer l.Close()
+	cmd := exec.Command(dockerBinary, "run", "-p", port+":80", "busybox", "true")
+	out, _, err := runCommandWithOutput(cmd)
+	if err == nil {
+		t.Fatalf("Host port %s already in use, has been allocated by docker: %q", port, out)
+	}
+
+	deleteAllContainers()
+
+	logDone("run - port in use")
+}