forked from feixiao/docker1.2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_cli_attach_test.go
53 lines (44 loc) · 1018 Bytes
/
docker_cli_attach_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"os/exec"
"strings"
"sync"
"testing"
"time"
)
func TestMultipleAttachRestart(t *testing.T) {
cmd := exec.Command(dockerBinary, "run", "--name", "attacher", "-d", "busybox",
"/bin/sh", "-c", "sleep 2 && echo hello")
group := sync.WaitGroup{}
group.Add(4)
defer func() {
cmd = exec.Command(dockerBinary, "kill", "attacher")
if _, err := runCommand(cmd); err != nil {
t.Fatal(err)
}
deleteAllContainers()
}()
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()
logDone("attach - multiple attach")
}