Use sync.WaitGroup to control concurrent tests

pull/4/head
Stephen J Day 2014-12-02 20:43:31 -08:00
parent 66107df1af
commit b047c92e1c
1 changed files with 5 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"path" "path"
"sort" "sort"
"sync"
"testing" "testing"
"github.com/docker/docker-registry/storagedriver" "github.com/docker/docker-registry/storagedriver"
@ -386,13 +387,14 @@ func (suite *DriverSuite) TestConcurrentFileStreams(c *check.C) {
c.Skip("Need to fix out-of-process concurrency") c.Skip("Need to fix out-of-process concurrency")
} }
doneChan := make(chan struct{}) var wg sync.WaitGroup
testStream := func(size int64) { testStream := func(size int64) {
defer wg.Done()
suite.testFileStreams(c, size) suite.testFileStreams(c, size)
doneChan <- struct{}{}
} }
wg.Add(6)
go testStream(8 * 1024 * 1024) go testStream(8 * 1024 * 1024)
go testStream(4 * 1024 * 1024) go testStream(4 * 1024 * 1024)
go testStream(2 * 1024 * 1024) go testStream(2 * 1024 * 1024)
@ -400,10 +402,7 @@ func (suite *DriverSuite) TestConcurrentFileStreams(c *check.C) {
go testStream(1024) go testStream(1024)
go testStream(64) go testStream(64)
for i := 0; i < 6; i++ { wg.Wait()
<-doneChan
}
} }
func (suite *DriverSuite) testFileStreams(c *check.C, size int64) { func (suite *DriverSuite) testFileStreams(c *check.C, size int64) {