1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #10122 from dqminh/execin-wait-cgroup

ExecIn process should wait for the parent signal before forking
This commit is contained in:
Michael Crosby 2015-01-20 18:02:14 -08:00
commit 5f5e02d22c

View file

@ -2,9 +2,13 @@ package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"reflect"
"sort"
"strings"
"sync"
"testing"
"time"
)
@ -392,3 +396,60 @@ func TestExecStopNotHanging(t *testing.T) {
}
logDone("exec - container with exec not hanging on stop")
}
func TestExecCgroup(t *testing.T) {
defer deleteAllContainers()
var cmd *exec.Cmd
cmd = exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "top")
_, err := runCommand(cmd)
if err != nil {
t.Fatal(err)
}
cmd = exec.Command(dockerBinary, "exec", "testing", "cat", "/proc/1/cgroup")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(out, err)
}
containerCgroups := sort.StringSlice(strings.Split(string(out), "\n"))
var wg sync.WaitGroup
var s sync.Mutex
execCgroups := []sort.StringSlice{}
// exec a few times concurrently to get consistent failure
for i := 0; i < 5; i++ {
wg.Add(1)
go func() {
cmd = exec.Command(dockerBinary, "exec", "testing", "cat", "/proc/self/cgroup")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(out, err)
}
cg := sort.StringSlice(strings.Split(string(out), "\n"))
s.Lock()
execCgroups = append(execCgroups, cg)
s.Unlock()
wg.Done()
}()
}
wg.Wait()
for _, cg := range execCgroups {
if !reflect.DeepEqual(cg, containerCgroups) {
fmt.Println("exec cgroups:")
for _, name := range cg {
fmt.Printf(" %s\n", name)
}
fmt.Println("container cgroups:")
for _, name := range containerCgroups {
fmt.Printf(" %s\n", name)
}
t.Fatal("cgroups mismatched")
}
}
logDone("exec - exec has the container cgroups")
}