integration-cli/benchmark_test.go
65d79e3e
 package main
 
 import (
 	"fmt"
 	"io/ioutil"
 	"os"
 	"runtime"
 	"strings"
 	"sync"
e25352a4
 	"testing"
65d79e3e
 
6345208b
 	"gotest.tools/assert"
65d79e3e
 )
 
4a358d07
 func (s *DockerSuite) BenchmarkConcurrentContainerActions(c *testing.B) {
65d79e3e
 	maxConcurrency := runtime.GOMAXPROCS(0)
 	numIterations := c.N
 	outerGroup := &sync.WaitGroup{}
 	outerGroup.Add(maxConcurrency)
 	chErr := make(chan error, numIterations*2*maxConcurrency)
 
 	for i := 0; i < maxConcurrency; i++ {
 		go func() {
 			defer outerGroup.Done()
 			innerGroup := &sync.WaitGroup{}
 			innerGroup.Add(2)
 
 			go func() {
 				defer innerGroup.Done()
 				for i := 0; i < numIterations; i++ {
a63a02fe
 					args := []string{"run", "-d", "busybox"}
52f04748
 					args = append(args, sleepCommandForDaemonPlatform()...)
65d79e3e
 					out, _, err := dockerCmdWithError(args...)
 					if err != nil {
 						chErr <- fmt.Errorf(out)
 						return
 					}
 
 					id := strings.TrimSpace(out)
 					tmpDir, err := ioutil.TempDir("", "docker-concurrent-test-"+id)
 					if err != nil {
 						chErr <- err
 						return
 					}
 					defer os.RemoveAll(tmpDir)
 					out, _, err = dockerCmdWithError("cp", id+":/tmp", tmpDir)
 					if err != nil {
 						chErr <- fmt.Errorf(out)
 						return
 					}
 
 					out, _, err = dockerCmdWithError("kill", id)
 					if err != nil {
 						chErr <- fmt.Errorf(out)
 					}
 
 					out, _, err = dockerCmdWithError("start", id)
 					if err != nil {
 						chErr <- fmt.Errorf(out)
 					}
 
 					out, _, err = dockerCmdWithError("kill", id)
 					if err != nil {
 						chErr <- fmt.Errorf(out)
 					}
 
 					// don't do an rm -f here since it can potentially ignore errors from the graphdriver
 					out, _, err = dockerCmdWithError("rm", id)
 					if err != nil {
 						chErr <- fmt.Errorf(out)
 					}
 				}
 			}()
 
 			go func() {
 				defer innerGroup.Done()
 				for i := 0; i < numIterations; i++ {
 					out, _, err := dockerCmdWithError("ps")
 					if err != nil {
 						chErr <- fmt.Errorf(out)
 					}
 				}
 			}()
 
 			innerGroup.Wait()
 		}()
 	}
 
 	outerGroup.Wait()
 	close(chErr)
 
 	for err := range chErr {
6345208b
 		assert.NilError(c, err)
65d79e3e
 	}
 }