test: add buffer to prevent goroutine leak

Signed-off-by: Ziheng Liu <lzhfromustc@gmail.com>
This commit is contained in:
Ziheng Liu
2020-02-25 17:13:25 -05:00
parent d706420b5d
commit c322af8019
22 changed files with 63 additions and 45 deletions

View File

@@ -177,6 +177,8 @@ func (s *DockerSwarmSuite) TestServiceLogsFollow(c *testing.T) {
// Make sure pipe is written to
ch := make(chan *logMessage)
done := make(chan struct{})
stop := make(chan struct{})
defer close(stop)
go func() {
reader := bufio.NewReader(r)
for {
@@ -184,6 +186,8 @@ func (s *DockerSwarmSuite) TestServiceLogsFollow(c *testing.T) {
msg.data, _, msg.err = reader.ReadLine()
select {
case ch <- msg:
case <-stop:
return
case <-done:
return
}