agent/proxy: make the logs test a bit more robust by waiting for file
This commit is contained in:
parent
d019d33bc6
commit
e2133fd391
|
@ -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"
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue