From 9ac1ad0fcf0ca73b9c87db863c1e21bedc7cf19a Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Wed, 20 May 2015 20:10:10 +0300 Subject: [PATCH] integration: don't ignore exit codes of test processes Signed-off-by: Andrey Vagin --- integration/exec_test.go | 29 +++++------------------------ integration/execin_test.go | 38 ++++++++++++++++---------------------- integration/utils_test.go | 13 +++++++++++++ 3 files changed, 34 insertions(+), 46 deletions(-) diff --git a/integration/exec_test.go b/integration/exec_test.go index fea5f7ee..20d781ee 100644 --- a/integration/exec_test.go +++ b/integration/exec_test.go @@ -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) { diff --git a/integration/execin_test.go b/integration/execin_test.go index f81faf01..7ff3975f 100644 --- a/integration/execin_test.go +++ b/integration/execin_test.go @@ -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") || diff --git a/integration/utils_test.go b/integration/utils_test.go index ffd7130b..41b914ca 100644 --- a/integration/utils_test.go +++ b/integration/utils_test.go @@ -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("", "")