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

test that execin cgroups match container cgroups

Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com>
This commit is contained in:
Daniel, Dao Quang Minh 2015-01-15 13:37:30 -05:00
parent e9d3e237e5
commit 9462dbb242

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")
}