integration: don't ignore exit codes of test processes

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2015-05-20 20:10:10 +03:00
parent a4a648ce30
commit 9ac1ad0fcf
3 changed files with 34 additions and 46 deletions

View File

@ -182,14 +182,6 @@ func newTestRoot() (string, error) {
return dir, nil
}
func waitProcess(p *libcontainer.Process, t *testing.T) {
status, err := p.Wait()
ok(t, err)
if !status.Success() {
t.Fatal(status)
}
}
func TestEnter(t *testing.T) {
if testing.Short() {
return
@ -430,22 +422,16 @@ func testFreeze(t *testing.T, systemd bool) {
stdinR, stdinW, err := os.Pipe()
ok(t, err)
pconfig := libcontainer.Process{
pconfig := &libcontainer.Process{
Args: []string{"cat"},
Env: standardEnvironment,
Stdin: stdinR,
}
err = container.Start(&pconfig)
err = container.Start(pconfig)
stdinR.Close()
defer stdinW.Close()
ok(t, err)
pid, err := pconfig.Pid()
ok(t, err)
process, err := os.FindProcess(pid)
ok(t, err)
err = container.Pause()
ok(t, err)
state, err := container.Status()
@ -457,12 +443,7 @@ func testFreeze(t *testing.T, systemd bool) {
}
stdinW.Close()
s, err := process.Wait()
ok(t, err)
if !s.Success() {
t.Fatal(s.String())
}
waitProcess(pconfig, t)
}
func TestCpuShares(t *testing.T) {
@ -547,7 +528,7 @@ func TestContainerState(t *testing.T) {
t.Fatal(err)
}
stdinR.Close()
defer p.Signal(os.Kill)
defer stdinW.Close()
st, err := container.State()
if err != nil {
@ -562,7 +543,7 @@ func TestContainerState(t *testing.T) {
t.Fatal("Container using non-host ipc namespace")
}
stdinW.Close()
p.Wait()
waitProcess(p, t)
}
func TestPassExtraFiles(t *testing.T) {

View File

@ -44,14 +44,13 @@ func TestExecIn(t *testing.T) {
Stdout: buffers.Stdout,
Stderr: buffers.Stderr,
}
err = container.Start(ps)
ok(t, err)
_, err = ps.Wait()
ok(t, err)
waitProcess(ps, t)
stdinW.Close()
if _, err := process.Wait(); err != nil {
t.Log(err)
}
waitProcess(process, t)
out := buffers.Stdout.String()
if !strings.Contains(out, "cat") || !strings.Contains(out, "ps") {
t.Fatalf("unexpected running process, output %q", out)
@ -92,12 +91,11 @@ func TestExecInRlimit(t *testing.T) {
}
err = container.Start(ps)
ok(t, err)
_, err = ps.Wait()
ok(t, err)
waitProcess(ps, t)
stdinW.Close()
if _, err := process.Wait(); err != nil {
t.Log(err)
}
waitProcess(process, t)
out := buffers.Stdout.String()
if limit := strings.TrimSpace(out); limit != "1025" {
t.Fatalf("expected rlimit to be 1025, got %s", limit)
@ -191,12 +189,11 @@ func TestExecInTTY(t *testing.T) {
t.Fatal("Waiting for copy timed out")
case <-copy:
}
_, err = ps.Wait()
ok(t, err)
waitProcess(ps, t)
stdinW.Close()
if _, err := process.Wait(); err != nil {
t.Log(err)
}
waitProcess(process, t)
out := stdout.String()
if !strings.Contains(out, "cat") || !strings.Contains(string(out), "ps") {
t.Fatalf("unexpected running process, output %q", out)
@ -243,14 +240,11 @@ func TestExecInEnvironment(t *testing.T) {
}
err = container.Start(process2)
ok(t, err)
if _, err := process2.Wait(); err != nil {
out := buffers.Stdout.String()
t.Fatal(err, out)
}
waitProcess(process2, t)
stdinW.Close()
if _, err := process.Wait(); err != nil {
t.Log(err)
}
waitProcess(process, t)
out := buffers.Stdout.String()
// check execin's process environment
if !strings.Contains(out, "DEBUG=false") ||

View File

@ -49,6 +49,19 @@ func ok(t testing.TB, err error) {
}
}
func waitProcess(p *libcontainer.Process, t *testing.T) {
_, file, line, _ := runtime.Caller(1)
status, err := p.Wait()
if err != nil {
t.Fatalf("%s:%d: unexpected error: %s\n\n", filepath.Base(file), line, err.Error())
}
if !status.Success() {
t.Fatalf("%s:%d: unexpected status: %s\n\n", filepath.Base(file), line, status.String())
}
}
// newRootfs creates a new tmp directory and copies the busybox root filesystem
func newRootfs() (string, error) {
dir, err := ioutil.TempDir("", "")