mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-06 13:41:36 +00:00
remove some uneeded sleeps in tests
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user