Remove ChannelBuffer

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 6a0105b452e604866320aad7e2ad291beb7925b9
Component: engine
This commit is contained in:
Daniel Nephin
2017-08-22 17:15:26 -04:00
parent 594cd7054e
commit 5e635809d5
3 changed files with 29 additions and 75 deletions
@@ -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)