refactor common container setup out of execin tests
Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com> (github: dqminh)
This commit is contained in:
parent
0195469398
commit
6a76ecb1ce
|
@ -27,28 +27,7 @@ func TestExecIn(t *testing.T) {
|
||||||
t.Fatalf("failed to write config %s", err)
|
t.Fatalf("failed to write config %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// start the container
|
containerCmd, statePath, containerErr := startLongRunningContainer(config)
|
||||||
containerErr := make(chan error, 1)
|
|
||||||
containerCmd := &exec.Cmd{}
|
|
||||||
var statePath string
|
|
||||||
createCmd := func(container *libcontainer.Config, console, dataPath, init string,
|
|
||||||
pipe *os.File, args []string) *exec.Cmd {
|
|
||||||
containerCmd = namespaces.DefaultCreateCommand(container, console, dataPath, init, pipe, args)
|
|
||||||
statePath = dataPath
|
|
||||||
return containerCmd
|
|
||||||
}
|
|
||||||
var containerStart sync.WaitGroup
|
|
||||||
containerStart.Add(1)
|
|
||||||
go func() {
|
|
||||||
buffers := newStdBuffers()
|
|
||||||
_, err := namespaces.Exec(config,
|
|
||||||
buffers.Stdin, buffers.Stdout, buffers.Stderr,
|
|
||||||
"", config.RootFs, []string{"sleep", "10"},
|
|
||||||
createCmd, containerStart.Done)
|
|
||||||
containerErr <- err
|
|
||||||
}()
|
|
||||||
containerStart.Wait()
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
// kill the container
|
// kill the container
|
||||||
if containerCmd.Process != nil {
|
if containerCmd.Process != nil {
|
||||||
|
@ -98,28 +77,7 @@ func TestExecInRlimit(t *testing.T) {
|
||||||
t.Fatalf("failed to write config %s", err)
|
t.Fatalf("failed to write config %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// start the container
|
containerCmd, statePath, containerErr := startLongRunningContainer(config)
|
||||||
containerErr := make(chan error, 1)
|
|
||||||
containerCmd := &exec.Cmd{}
|
|
||||||
var statePath string
|
|
||||||
createCmd := func(container *libcontainer.Config, console, dataPath, init string,
|
|
||||||
pipe *os.File, args []string) *exec.Cmd {
|
|
||||||
containerCmd = namespaces.DefaultCreateCommand(container, console, dataPath, init, pipe, args)
|
|
||||||
statePath = dataPath
|
|
||||||
return containerCmd
|
|
||||||
}
|
|
||||||
var containerStart sync.WaitGroup
|
|
||||||
containerStart.Add(1)
|
|
||||||
go func() {
|
|
||||||
buffers := newStdBuffers()
|
|
||||||
_, err := namespaces.Exec(config,
|
|
||||||
buffers.Stdin, buffers.Stdout, buffers.Stderr,
|
|
||||||
"", config.RootFs, []string{"sleep", "10"},
|
|
||||||
createCmd, containerStart.Done)
|
|
||||||
containerErr <- err
|
|
||||||
}()
|
|
||||||
containerStart.Wait()
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
// kill the container
|
// kill the container
|
||||||
if containerCmd.Process != nil {
|
if containerCmd.Process != nil {
|
||||||
|
@ -152,3 +110,31 @@ func TestExecInRlimit(t *testing.T) {
|
||||||
t.Fatalf("expected rlimit to be 1024, got %s", limit)
|
t.Fatalf("expected rlimit to be 1024, got %s", limit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start a long-running container so we have time to inspect execin processes
|
||||||
|
func startLongRunningContainer(config *libcontainer.Config) (*exec.Cmd, string, chan error) {
|
||||||
|
containerErr := make(chan error, 1)
|
||||||
|
containerCmd := &exec.Cmd{}
|
||||||
|
var statePath string
|
||||||
|
|
||||||
|
createCmd := func(container *libcontainer.Config, console, dataPath, init string,
|
||||||
|
pipe *os.File, args []string) *exec.Cmd {
|
||||||
|
containerCmd = namespaces.DefaultCreateCommand(container, console, dataPath, init, pipe, args)
|
||||||
|
statePath = dataPath
|
||||||
|
return containerCmd
|
||||||
|
}
|
||||||
|
|
||||||
|
var containerStart sync.WaitGroup
|
||||||
|
containerStart.Add(1)
|
||||||
|
go func() {
|
||||||
|
buffers := newStdBuffers()
|
||||||
|
_, err := namespaces.Exec(config,
|
||||||
|
buffers.Stdin, buffers.Stdout, buffers.Stderr,
|
||||||
|
"", config.RootFs, []string{"sleep", "10"},
|
||||||
|
createCmd, containerStart.Done)
|
||||||
|
containerErr <- err
|
||||||
|
}()
|
||||||
|
containerStart.Wait()
|
||||||
|
|
||||||
|
return containerCmd, statePath, containerErr
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue