From 1455086c4b922f09777aa49ec26a98c463be6a49 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 21 Aug 2017 18:58:25 -0400 Subject: [PATCH] Remove ConsumeWithSpeed Signed-off-by: Daniel Nephin --- integration-cli/docker_cli_logs_test.go | 27 ++++++++++++++++-- integration-cli/docker_cli_run_test.go | 2 +- pkg/testutil/utils.go | 25 ---------------- pkg/testutil/utils_test.go | 38 ------------------------- 4 files changed, 26 insertions(+), 66 deletions(-) diff --git a/integration-cli/docker_cli_logs_test.go b/integration-cli/docker_cli_logs_test.go index a8b8f90548..435411e528 100644 --- a/integration-cli/docker_cli_logs_test.go +++ b/integration-cli/docker_cli_logs_test.go @@ -232,11 +232,11 @@ func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *check.C) { c.Assert(logCmd.Start(), checker.IsNil) // First read slowly - bytes1, err := testutil.ConsumeWithSpeed(stdout, 10, 50*time.Millisecond, stopSlowRead) + bytes1, err := ConsumeWithSpeed(stdout, 10, 50*time.Millisecond, stopSlowRead) c.Assert(err, checker.IsNil) // After the container has finished we can continue reading fast - bytes2, err := testutil.ConsumeWithSpeed(stdout, 32*1024, 0, nil) + bytes2, err := ConsumeWithSpeed(stdout, 32*1024, 0, nil) c.Assert(err, checker.IsNil) actual := bytes1 + bytes2 @@ -244,6 +244,29 @@ func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *check.C) { c.Assert(actual, checker.Equals, expected) } +// ConsumeWithSpeed reads chunkSize bytes from reader before sleeping +// for interval duration. Returns total read bytes. Send true to the +// stop channel to return before reading to EOF on the reader. +func ConsumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, err error) { + buffer := make([]byte, chunkSize) + for { + var readBytes int + readBytes, err = reader.Read(buffer) + n += readBytes + if err != nil { + if err == io.EOF { + err = nil + } + return + } + select { + case <-stop: + return + case <-time.After(interval): + } + } +} + func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *check.C) { out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 2; done") id := strings.TrimSpace(out) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index d080086f78..121f0220c3 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -2247,7 +2247,7 @@ func (s *DockerSuite) TestRunSlowStdoutConsumer(c *check.C) { if err := cont.Start(); err != nil { c.Fatal(err) } - n, err := testutil.ConsumeWithSpeed(stdout, 10000, 5*time.Millisecond, nil) + n, err := ConsumeWithSpeed(stdout, 10000, 5*time.Millisecond, nil) if err != nil { c.Fatal(err) } diff --git a/pkg/testutil/utils.go b/pkg/testutil/utils.go index edd5dfa314..c824442061 100644 --- a/pkg/testutil/utils.go +++ b/pkg/testutil/utils.go @@ -3,12 +3,10 @@ package testutil import ( "errors" "fmt" - "io" "os" "os/exec" "path/filepath" "strings" - "time" "github.com/docker/docker/pkg/stringutils" "github.com/docker/docker/pkg/system" @@ -80,29 +78,6 @@ func RandomTmpDirPath(s string, platform string) string { return filepath.ToSlash(path) // Using / } -// ConsumeWithSpeed reads chunkSize bytes from reader before sleeping -// for interval duration. Returns total read bytes. Send true to the -// stop channel to return before reading to EOF on the reader. -func ConsumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, err error) { - buffer := make([]byte, chunkSize) - for { - var readBytes int - readBytes, err = reader.Read(buffer) - n += readBytes - if err != nil { - if err == io.EOF { - err = nil - } - return - } - select { - case <-stop: - return - case <-time.After(interval): - } - } -} - // ParseCgroupPaths parses 'procCgroupData', which is output of '/proc//cgroup', and returns // a map which cgroup name as key and path as value. func ParseCgroupPaths(procCgroupData string) map[string]string { diff --git a/pkg/testutil/utils_test.go b/pkg/testutil/utils_test.go index fb55dbdf3f..929d53542e 100644 --- a/pkg/testutil/utils_test.go +++ b/pkg/testutil/utils_test.go @@ -6,7 +6,6 @@ import ( "runtime" "strings" "testing" - "time" ) func TestRunCommandPipelineWithOutputWithNotEnoughCmds(t *testing.T) { @@ -73,43 +72,6 @@ func TestRandomTmpDirPath(t *testing.T) { } } -func TestConsumeWithSpeed(t *testing.T) { - reader := strings.NewReader("1234567890") - chunksize := 2 - - bytes1, err := ConsumeWithSpeed(reader, chunksize, 10*time.Millisecond, nil) - if err != nil { - t.Fatal(err) - } - - if bytes1 != 10 { - t.Fatalf("Expected to have read 10 bytes, got %d", bytes1) - } - -} - -func TestConsumeWithSpeedWithStop(t *testing.T) { - reader := strings.NewReader("1234567890") - chunksize := 2 - - stopIt := make(chan bool) - - go func() { - time.Sleep(1 * time.Millisecond) - stopIt <- true - }() - - bytes1, err := ConsumeWithSpeed(reader, chunksize, 20*time.Millisecond, stopIt) - if err != nil { - t.Fatal(err) - } - - if bytes1 != 2 { - t.Fatalf("Expected to have read 2 bytes, got %d", bytes1) - } - -} - func TestParseCgroupPathsEmpty(t *testing.T) { cgroupMap := ParseCgroupPaths("") if len(cgroupMap) != 0 {