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

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

@ -53,7 +53,7 @@ func (s *DockerSuite) TestExecInteractive(c *testing.T) {
assert.Equal(c, line, "test")
err = stdin.Close()
assert.NilError(c, err)
errChan := make(chan error)
errChan := make(chan error, 1)
go func() {
errChan <- execCmd.Wait()
close(errChan)
@ -170,7 +170,7 @@ func (s *DockerSuite) TestExecTTYWithoutStdin(c *testing.T) {
id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id))
errChan := make(chan error)
errChan := make(chan error, 1)
go func() {
defer close(errChan)
@ -230,7 +230,7 @@ func (s *DockerSuite) TestExecStopNotHanging(c *testing.T) {
out string
err error
}
ch := make(chan dstop)
ch := make(chan dstop, 1)
go func() {
result := icmd.RunCommand(dockerBinary, "stop", "testing")
ch <- dstop{result.Combined(), result.Error}
@ -256,11 +256,12 @@ func (s *DockerSuite) TestExecCgroup(c *testing.T) {
var wg sync.WaitGroup
var mu sync.Mutex
var execCgroups []sort.StringSlice
errChan := make(chan error)
errChan := make(chan error, 5)
// exec a few times concurrently to get consistent failure
for i := 0; i < 5; i++ {
wg.Add(1)
go func() {
defer wg.Done()
out, _, err := dockerCmdWithError("exec", "testing", "cat", "/proc/self/cgroup")
if err != nil {
errChan <- err
@ -271,7 +272,6 @@ func (s *DockerSuite) TestExecCgroup(c *testing.T) {
mu.Lock()
execCgroups = append(execCgroups, cg)
mu.Unlock()
wg.Done()
}()
}
wg.Wait()