From a2fe60419165d29757585dd0c7d07a93d0432f6c Mon Sep 17 00:00:00 2001 From: Paul Banks Date: Mon, 4 Jun 2018 21:40:02 +0100 Subject: [PATCH] WIP --- agent/proxy/daemon_test.go | 7 ++++++- agent/proxy/proxy_test.go | 16 +++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/agent/proxy/daemon_test.go b/agent/proxy/daemon_test.go index e4db631808..d4ef4f4ae7 100644 --- a/agent/proxy/daemon_test.go +++ b/agent/proxy/daemon_test.go @@ -121,12 +121,17 @@ func TestDaemonDetachesChild(t *testing.T) { proc.Kill() }() + time.Sleep(20 * time.Second) + // Now kill the parent and wait for it require.NoError(parentCmd.Process.Kill()) + _, err := parentCmd.Process.Wait() require.NoError(err) - // The child should still be running so file should still be there + time.Sleep(15 * time.Second) + + // The child should still be running so file should still be there AND child processid should still be there _, err = os.Stat(path) require.NoError(err, "child should still be running") diff --git a/agent/proxy/proxy_test.go b/agent/proxy/proxy_test.go index 6c882a517d..34bdc89fa2 100644 --- a/agent/proxy/proxy_test.go +++ b/agent/proxy/proxy_test.go @@ -178,12 +178,13 @@ func TestHelperProcess(t *testing.T) { <-make(chan struct{}) - // Parent runs the given process in a Daemon and then exits. It exists to test - // that the Daemon-managed child process survives it's parent exiting which we - // can't test directly without exiting the test process so we need an extra - // level of indirection. The caller must pass a file path as the first - // argument for the child processes PID to be written and then must take care - // to clean up that PID later or the child will be left running forever. + // Parent runs the given process in a Daemon and then sleeps until the test + // code kills it. It exists to test that the Daemon-managed child process + // survives it's parent exiting which we can't test directly without exiting + // the test process so we need an extra level of indirection. The test code + // using this must pass a file path as the first argument for the child + // processes PID to be written and then must take care to clean up that PID + // later or the child will be left running forever. case "parent": // We will write the PID for the child to the file in the first argument // then pass rest of args through to command. @@ -197,10 +198,11 @@ func TestHelperProcess(t *testing.T) { pidBs := []byte(strconv.Itoa(d.Process.Pid)) if err := ioutil.WriteFile(pidFile, pidBs, 0644); err != nil { fmt.Fprintf(os.Stderr, "Error: %s\n", err) + // TODO: Also kill the detached process (once it is detached) os.Exit(1) } // Wait "forever" (calling test chooses when we exit with signal/Wait to - // minimise coordination) + // minimise coordination). for { time.Sleep(time.Hour) }