agent/proxy: make the logs test a bit more robust by waiting for file

This commit is contained in:
Mitchell Hashimoto 2018-05-02 20:16:29 -07:00
parent d019d33bc6
commit e2133fd391
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 15 additions and 6 deletions

View File

@ -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"

View File

@ -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: