зеркало из https://github.com/microsoft/docker.git
remove some uneeded sleeps in tests
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Родитель
310fc37fe7
Коммит
9e0ffae864
|
@ -1,28 +1,46 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) {
|
||||
name := "logs_test"
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "--name", name, "busybox", "bin/sh", "-c", "sleep 10 && echo "+name)
|
||||
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
||||
c.Fatal(out, err)
|
||||
out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done")
|
||||
id := strings.TrimSpace(out)
|
||||
if err := waitRun(id); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", name), nil)
|
||||
c.Assert(status, check.Equals, http.StatusOK)
|
||||
c.Assert(err, check.IsNil)
|
||||
type logOut struct {
|
||||
out string
|
||||
status int
|
||||
err error
|
||||
}
|
||||
chLog := make(chan logOut)
|
||||
|
||||
if !bytes.Contains(body, []byte(name)) {
|
||||
c.Fatalf("Expected %s, got %s", name, string(body[:]))
|
||||
go func() {
|
||||
statusCode, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", id), nil, "")
|
||||
out, _ := bufio.NewReader(body).ReadString('\n')
|
||||
chLog <- logOut{strings.TrimSpace(out), statusCode, err}
|
||||
}()
|
||||
|
||||
select {
|
||||
case l := <-chLog:
|
||||
c.Assert(l.status, check.Equals, http.StatusOK)
|
||||
c.Assert(l.err, check.IsNil)
|
||||
if !strings.HasSuffix(l.out, "hello") {
|
||||
c.Fatalf("expected log output to container 'hello', but it does not")
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
c.Fatal("timeout waiting for logs to exit")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,19 +44,29 @@ func (s *DockerSuite) TestWaitNonBlockedExitZero(c *check.C) {
|
|||
|
||||
// blocking wait with 0 exit code
|
||||
func (s *DockerSuite) TestWaitBlockedExitZero(c *check.C) {
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 10")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
c.Fatal(out, err)
|
||||
}
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 0' SIGTERM; while true; do sleep 0.01; done")
|
||||
containerID := strings.TrimSpace(out)
|
||||
|
||||
runCmd = exec.Command(dockerBinary, "wait", containerID)
|
||||
out, _, err = runCommandWithOutput(runCmd)
|
||||
if err := waitRun(containerID); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
if err != nil || strings.TrimSpace(out) != "0" {
|
||||
c.Fatal("failed to set up container", out, err)
|
||||
chWait := make(chan string)
|
||||
go func() {
|
||||
out, _, _ := runCommandWithOutput(exec.Command(dockerBinary, "wait", containerID))
|
||||
chWait <- out
|
||||
}()
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
dockerCmd(c, "stop", containerID)
|
||||
|
||||
select {
|
||||
case status := <-chWait:
|
||||
if strings.TrimSpace(status) != "0" {
|
||||
c.Fatalf("expected exit 0, got %s", status)
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
c.Fatal("timeout waiting for `docker wait` to exit")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -97,19 +107,30 @@ func (s *DockerSuite) TestWaitNonBlockedExitRandom(c *check.C) {
|
|||
|
||||
// blocking wait with random exit code
|
||||
func (s *DockerSuite) TestWaitBlockedExitRandom(c *check.C) {
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 10; exit 99")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
c.Fatal(out, err)
|
||||
}
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "trap 'exit 99' SIGTERM; while true; do sleep 0.01; done")
|
||||
containerID := strings.TrimSpace(out)
|
||||
|
||||
runCmd = exec.Command(dockerBinary, "wait", containerID)
|
||||
out, _, err = runCommandWithOutput(runCmd)
|
||||
|
||||
if err != nil || strings.TrimSpace(out) != "99" {
|
||||
c.Fatal("failed to set up container", out, err)
|
||||
if err := waitRun(containerID); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
if err := waitRun(containerID); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
chWait := make(chan string)
|
||||
go func() {
|
||||
out, _, _ := runCommandWithOutput(exec.Command(dockerBinary, "wait", containerID))
|
||||
chWait <- out
|
||||
}()
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
dockerCmd(c, "stop", containerID)
|
||||
|
||||
select {
|
||||
case status := <-chWait:
|
||||
if strings.TrimSpace(status) != "99" {
|
||||
c.Fatalf("expected exit 99, got %s", status)
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
c.Fatal("timeout waiting for `docker wait` to exit")
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче