From 34cc7a70adb5dc3009d330624c4fb6aa94841938 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Mon, 9 Jan 2017 15:40:53 -0800 Subject: [PATCH] Switch to a less timing dependent test command `/usr/bin/yes` could produce output very quickly (100s of MBps on my laptop) and therefore could cause log files to roll over. A bash loop with a sleep avoids that issue. The test is slower but should be much more resilient to the massive timing differences between workstations and Travis. --- client/driver/executor/executor_linux_test.go | 2 +- client/driver/executor/executor_test.go | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/client/driver/executor/executor_linux_test.go b/client/driver/executor/executor_linux_test.go index ac9c62b5c..751de540a 100644 --- a/client/driver/executor/executor_linux_test.go +++ b/client/driver/executor/executor_linux_test.go @@ -32,7 +32,7 @@ func testExecutorContextWithChroot(t *testing.T) (*ExecutorContext, *allocdir.Al "/bin/ls": "/bin/ls", "/bin/echo": "/bin/echo", "/bin/bash": "/bin/bash", - "/usr/bin/yes": "/usr/bin/yes", + "/bin/sleep": "/bin/sleep", "/foobar": "/does/not/exist", } diff --git a/client/driver/executor/executor_test.go b/client/driver/executor/executor_test.go index 525c86233..d9af1eb0c 100644 --- a/client/driver/executor/executor_test.go +++ b/client/driver/executor/executor_test.go @@ -190,22 +190,24 @@ func TestExecutor_WaitExitSignal(t *testing.T) { func TestExecutor_ClientCleanup(t *testing.T) { testutil.ExecCompatible(t) - execCmd := ExecCommand{Cmd: "/bin/bash", Args: []string{"-c", "/usr/bin/yes"}} ctx, allocDir := testExecutorContextWithChroot(t) ctx.Task.LogConfig.MaxFiles = 1 ctx.Task.LogConfig.MaxFileSizeMB = 300 defer allocDir.Destroy() - execCmd.FSIsolation = true - execCmd.ResourceLimits = true - execCmd.User = "nobody" - executor := NewExecutor(log.New(os.Stdout, "", log.LstdFlags)) if err := executor.SetContext(ctx); err != nil { t.Fatalf("Unexpected error") } + // Need to run a command which will produce continuous output but not + // too quickly to ensure executor.Exit() stops the process. + execCmd := ExecCommand{Cmd: "/bin/bash", Args: []string{"-c", "while true; do /bin/echo X; /bin/sleep 1; done"}} + execCmd.FSIsolation = true + execCmd.ResourceLimits = true + execCmd.User = "nobody" + ps, err := executor.LaunchCmd(&execCmd) if err != nil { t.Fatalf("error in launching command: %v", err) @@ -213,7 +215,7 @@ func TestExecutor_ClientCleanup(t *testing.T) { if ps.Pid == 0 { t.Fatalf("expected process to start and have non zero pid") } - time.Sleep(200 * time.Millisecond) + time.Sleep(500 * time.Millisecond) if err := executor.Exit(); err != nil { t.Fatalf("err: %v", err) } @@ -223,7 +225,10 @@ func TestExecutor_ClientCleanup(t *testing.T) { if err != nil { t.Fatalf("error stating stdout file: %v", err) } - time.Sleep(1 * time.Second) + if finfo.Size() == 0 { + t.Fatal("Nothing in stdout; expected at least one byte.") + } + time.Sleep(2 * time.Second) finfo1, err := os.Stat(file) if err != nil { t.Fatalf("error stating stdout file: %v", err)