When doing `docker start -a` on a container that won't start, terminal
was getting stuck on the attach, even after container removal.
Docker-DCO-1.1-Signed-off-by: Brian Goff <cpuguy83@gmail.com> (github: cpuguy83)
| 671 | 670 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,38 @@ |
| 0 |
+package main |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "os/exec" |
|
| 4 |
+ "testing" |
|
| 5 |
+ "time" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+// Regression test for https://github.com/docker/docker/issues/7843 |
|
| 9 |
+func TestStartAttachReturnsOnError(t *testing.T) {
|
|
| 10 |
+ defer deleteAllContainers() |
|
| 11 |
+ |
|
| 12 |
+ cmd(t, "run", "-d", "--name", "test", "busybox") |
|
| 13 |
+ cmd(t, "stop", "test") |
|
| 14 |
+ |
|
| 15 |
+ // Expect this to fail because the above container is stopped, this is what we want |
|
| 16 |
+ if _, err := runCommand(exec.Command(dockerBinary, "run", "-d", "--name", "test2", "--link", "test:test", "busybox")); err == nil {
|
|
| 17 |
+ t.Fatal("Expected error but got none")
|
|
| 18 |
+ } |
|
| 19 |
+ |
|
| 20 |
+ ch := make(chan struct{})
|
|
| 21 |
+ go func() {
|
|
| 22 |
+ // Attempt to start attached to the container that won't start |
|
| 23 |
+ // This should return an error immediately since the container can't be started |
|
| 24 |
+ if _, err := runCommand(exec.Command(dockerBinary, "start", "-a", "test2")); err == nil {
|
|
| 25 |
+ t.Fatal("Expected error but got none")
|
|
| 26 |
+ } |
|
| 27 |
+ close(ch) |
|
| 28 |
+ }() |
|
| 29 |
+ |
|
| 30 |
+ select {
|
|
| 31 |
+ case <-ch: |
|
| 32 |
+ case <-time.After(time.Second): |
|
| 33 |
+ t.Fatalf("Attach did not exit properly")
|
|
| 34 |
+ } |
|
| 35 |
+ |
|
| 36 |
+ logDone("start - error on start with attach exits")
|
|
| 37 |
+} |