From 5e6bd8291cf68ff62e5a937738c06e0218db05ae Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 2 May 2018 20:16:29 -0700 Subject: [PATCH] agent/proxy: make the logs test a bit more robust by waiting for file --- agent/proxy/manager_test.go | 9 +++------ agent/proxy/proxy_test.go | 12 ++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/agent/proxy/manager_test.go b/agent/proxy/manager_test.go index 0b56402419..3bf200805a 100644 --- a/agent/proxy/manager_test.go +++ b/agent/proxy/manager_test.go @@ -203,7 +203,8 @@ func TestManagerRun_daemonLogs(t *testing.T) { m.LogDir = filepath.Join(td, "logs") // Create the service and calculate the log paths - id := testStateProxy(t, state, "web", helperProcess("output")) + path := filepath.Join(td, "notify") + id := testStateProxy(t, state, "web", helperProcess("output", path)) stdoutPath := logPath(m.LogDir, id, "stdout") stderrPath := logPath(m.LogDir, id, "stderr") @@ -212,13 +213,9 @@ func TestManagerRun_daemonLogs(t *testing.T) { // We should see the path appear shortly retry.Run(t, func(r *retry.R) { - if _, err := os.Stat(stdoutPath); err != nil { + if _, err := os.Stat(path); err != nil { r.Fatalf("error waiting for stdout path: %s", err) } - - if _, err := os.Stat(stderrPath); err != nil { - r.Fatalf("error waiting for stderr path: %s", err) - } }) expectedOut := "hello stdout\n" diff --git a/agent/proxy/proxy_test.go b/agent/proxy/proxy_test.go index d79ea5bc89..d0812fc07c 100644 --- a/agent/proxy/proxy_test.go +++ b/agent/proxy/proxy_test.go @@ -141,6 +141,18 @@ func TestHelperProcess(t *testing.T) { case "output": fmt.Fprintf(os.Stdout, "hello stdout\n") fmt.Fprintf(os.Stderr, "hello stderr\n") + + // Sync to be sure it is written out of buffers + os.Stdout.Sync() + os.Stderr.Sync() + + // Output a file to signal we've written to stdout/err + path := args[0] + if err := ioutil.WriteFile(path, []byte("hello"), 0644); err != nil { + fmt.Fprintf(os.Stderr, "Error: %s\n", err) + os.Exit(1) + } + <-make(chan struct{}) default: