mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Port multiple attach test to cli tests
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
76a19bb3a9
commit
72f49e554f
2 changed files with 51 additions and 95 deletions
51
integration-cli/docker_cli_attach_test.go
Normal file
51
integration-cli/docker_cli_attach_test.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
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 1 && echo hello")
|
||||
|
||||
group := sync.WaitGroup{}
|
||||
group.Add(4)
|
||||
|
||||
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()
|
||||
|
||||
cmd = exec.Command(dockerBinary, "kill", "attacher")
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("run - multiple attach")
|
||||
}
|
|
@ -16,101 +16,6 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func TestMultipleAttachRestart(t *testing.T) {
|
||||
daemon := mkDaemon(t)
|
||||
defer nuke(daemon)
|
||||
container, _, _ := mkContainer(
|
||||
daemon,
|
||||
[]string{"_", "/bin/sh", "-c", "i=1; while [ $i -le 5 ]; do i=`expr $i + 1`; echo hello; done"},
|
||||
t,
|
||||
)
|
||||
defer daemon.Destroy(container)
|
||||
|
||||
// Simulate 3 client attaching to the container and stop/restart
|
||||
|
||||
stdout1, err := container.StdoutPipe()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stdout2, err := container.StdoutPipe()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stdout3, err := container.StdoutPipe()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := container.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
l1, err := bufio.NewReader(stdout1).ReadString('\n')
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Trim(l1, " \r\n") != "hello" {
|
||||
t.Fatalf("Unexpected output. Expected [%s], received [%s]", "hello", l1)
|
||||
}
|
||||
l2, err := bufio.NewReader(stdout2).ReadString('\n')
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Trim(l2, " \r\n") != "hello" {
|
||||
t.Fatalf("Unexpected output. Expected [%s], received [%s]", "hello", l2)
|
||||
}
|
||||
l3, err := bufio.NewReader(stdout3).ReadString('\n')
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Trim(l3, " \r\n") != "hello" {
|
||||
t.Fatalf("Unexpected output. Expected [%s], received [%s]", "hello", l3)
|
||||
}
|
||||
|
||||
if err := container.Stop(10); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
stdout1, err = container.StdoutPipe()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stdout2, err = container.StdoutPipe()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stdout3, err = container.StdoutPipe()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := container.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
setTimeout(t, "Timeout reading from the process", 3*time.Second, func() {
|
||||
l1, err = bufio.NewReader(stdout1).ReadString('\n')
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Trim(l1, " \r\n") != "hello" {
|
||||
t.Fatalf("Unexpected output. Expected [%s], received [%s]", "hello", l1)
|
||||
}
|
||||
l2, err = bufio.NewReader(stdout2).ReadString('\n')
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Trim(l2, " \r\n") != "hello" {
|
||||
t.Fatalf("Unexpected output. Expected [%s], received [%s]", "hello", l2)
|
||||
}
|
||||
l3, err = bufio.NewReader(stdout3).ReadString('\n')
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Trim(l3, " \r\n") != "hello" {
|
||||
t.Fatalf("Unexpected output. Expected [%s], received [%s]", "hello", l3)
|
||||
}
|
||||
})
|
||||
container.Wait()
|
||||
}
|
||||
|
||||
func TestDiff(t *testing.T) {
|
||||
eng := NewTestEngine(t)
|
||||
daemon := mkDaemonFromEngine(eng, t)
|
||||
|
|
Loading…
Add table
Reference in a new issue