1
0
mirror of https://github.com/moby/moby.git synced 2025-07-30 18:23:29 +03:00

Remove ChannelBuffer

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin
2017-08-21 18:44:50 -04:00
parent 6ffbe3f6a8
commit 6a0105b452
3 changed files with 29 additions and 75 deletions

View File

@ -215,7 +215,7 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
out := runSleepingContainer(c)
id := strings.TrimSpace(out)
buf := &testutil.ChannelBuffer{C: make(chan []byte, 1)}
buf := &ChannelBuffer{C: make(chan []byte, 1)}
defer buf.Close()
_, body, err := request.Get("/containers/"+id+"/stats?stream=1", request.JSON)
@ -243,6 +243,34 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
c.Assert(<-chErr, checker.IsNil)
}
// ChannelBuffer holds a chan of byte array that can be populate in a goroutine.
type ChannelBuffer struct {
C chan []byte
}
// Write implements Writer.
func (c *ChannelBuffer) Write(b []byte) (int, error) {
c.C <- b
return len(b), nil
}
// Close closes the go channel.
func (c *ChannelBuffer) Close() error {
close(c.C)
return nil
}
// ReadTimeout reads the content of the channel in the specified byte array with
// the specified duration as timeout.
func (c *ChannelBuffer) ReadTimeout(p []byte, n time.Duration) (int, error) {
select {
case b := <-c.C:
return copy(p[0:], b), nil
case <-time.After(n):
return -1, fmt.Errorf("timeout reading from channel")
}
}
// regression test for gh13421
// previous test was just checking one stat entry so it didn't fail (stats with
// stream false always return one stat)