зеркало из https://github.com/microsoft/docker.git
Remove ConsumeWithSpeed
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Родитель
4f304e72a2
Коммит
1455086c4b
|
@ -232,11 +232,11 @@ func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *check.C) {
|
||||||
c.Assert(logCmd.Start(), checker.IsNil)
|
c.Assert(logCmd.Start(), checker.IsNil)
|
||||||
|
|
||||||
// First read slowly
|
// 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)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
// After the container has finished we can continue reading fast
|
// 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)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
actual := bytes1 + bytes2
|
actual := bytes1 + bytes2
|
||||||
|
@ -244,6 +244,29 @@ func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *check.C) {
|
||||||
c.Assert(actual, checker.Equals, expected)
|
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) {
|
func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *check.C) {
|
||||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 2; done")
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 2; done")
|
||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
|
|
|
@ -2247,7 +2247,7 @@ func (s *DockerSuite) TestRunSlowStdoutConsumer(c *check.C) {
|
||||||
if err := cont.Start(); err != nil {
|
if err := cont.Start(); err != nil {
|
||||||
c.Fatal(err)
|
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 {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,10 @@ package testutil
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/stringutils"
|
"github.com/docker/docker/pkg/stringutils"
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
|
@ -80,29 +78,6 @@ func RandomTmpDirPath(s string, platform string) string {
|
||||||
return filepath.ToSlash(path) // Using /
|
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/<pid>/cgroup', and returns
|
// ParseCgroupPaths parses 'procCgroupData', which is output of '/proc/<pid>/cgroup', and returns
|
||||||
// a map which cgroup name as key and path as value.
|
// a map which cgroup name as key and path as value.
|
||||||
func ParseCgroupPaths(procCgroupData string) map[string]string {
|
func ParseCgroupPaths(procCgroupData string) map[string]string {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRunCommandPipelineWithOutputWithNotEnoughCmds(t *testing.T) {
|
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) {
|
func TestParseCgroupPathsEmpty(t *testing.T) {
|
||||||
cgroupMap := ParseCgroupPaths("")
|
cgroupMap := ParseCgroupPaths("")
|
||||||
if len(cgroupMap) != 0 {
|
if len(cgroupMap) != 0 {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче