mirror of
https://github.com/moby/moby.git
synced 2025-07-30 18:23:29 +03:00
@ -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)
|
||||
|
Reference in New Issue
Block a user