2014-04-18 02:14:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMultipleAttachRestart(t *testing.T) {
|
|
|
|
cmd := exec.Command(dockerBinary, "run", "--name", "attacher", "-d", "busybox",
|
2014-06-13 17:32:25 +00:00
|
|
|
"/bin/sh", "-c", "sleep 2 && echo hello")
|
2014-04-18 02:14:00 +00:00
|
|
|
|
|
|
|
group := sync.WaitGroup{}
|
|
|
|
group.Add(4)
|
|
|
|
|
2014-06-13 17:32:25 +00:00
|
|
|
defer func() {
|
|
|
|
cmd = exec.Command(dockerBinary, "kill", "attacher")
|
|
|
|
if _, err := runCommand(cmd); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
deleteAllContainers()
|
|
|
|
}()
|
|
|
|
|
2014-04-18 02:14:00 +00:00
|
|
|
go func() {
|
|
|
|
defer group.Done()
|
|
|
|
out, _, err := runCommandWithOutput(cmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err, out)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
|
|
|
|
for i := 0; i < 3; i++ {
|
|
|
|
go func() {
|
|
|
|
defer group.Done()
|
|
|
|
c := exec.Command(dockerBinary, "attach", "attacher")
|
|
|
|
|
|
|
|
out, _, err := runCommandWithOutput(c)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err, out)
|
|
|
|
}
|
|
|
|
if actual := strings.Trim(out, "\r\n"); actual != "hello" {
|
|
|
|
t.Fatalf("unexpected output %s expected hello", actual)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
group.Wait()
|
|
|
|
|
2014-06-13 17:32:25 +00:00
|
|
|
logDone("attach - multiple attach")
|
2014-04-18 02:14:00 +00:00
|
|
|
}
|