This commit is contained in:
Paul Banks 2018-06-04 21:40:02 +01:00 committed by Jack Pearkes
parent 8cf4b3a6eb
commit a2fe604191
2 changed files with 15 additions and 8 deletions

View File

@ -121,12 +121,17 @@ func TestDaemonDetachesChild(t *testing.T) {
proc.Kill() proc.Kill()
}() }()
time.Sleep(20 * time.Second)
// Now kill the parent and wait for it // Now kill the parent and wait for it
require.NoError(parentCmd.Process.Kill()) require.NoError(parentCmd.Process.Kill())
_, err := parentCmd.Process.Wait() _, err := parentCmd.Process.Wait()
require.NoError(err) 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) _, err = os.Stat(path)
require.NoError(err, "child should still be running") require.NoError(err, "child should still be running")

View File

@ -178,12 +178,13 @@ func TestHelperProcess(t *testing.T) {
<-make(chan struct{}) <-make(chan struct{})
// Parent runs the given process in a Daemon and then exits. It exists to test // Parent runs the given process in a Daemon and then sleeps until the test
// that the Daemon-managed child process survives it's parent exiting which we // code kills it. It exists to test that the Daemon-managed child process
// can't test directly without exiting the test process so we need an extra // survives it's parent exiting which we can't test directly without exiting
// level of indirection. The caller must pass a file path as the first // the test process so we need an extra level of indirection. The test code
// argument for the child processes PID to be written and then must take care // using this must pass a file path as the first argument for the child
// to clean up that PID later or the child will be left running forever. // 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": case "parent":
// We will write the PID for the child to the file in the first argument // We will write the PID for the child to the file in the first argument
// then pass rest of args through to command. // then pass rest of args through to command.
@ -197,10 +198,11 @@ func TestHelperProcess(t *testing.T) {
pidBs := []byte(strconv.Itoa(d.Process.Pid)) pidBs := []byte(strconv.Itoa(d.Process.Pid))
if err := ioutil.WriteFile(pidFile, pidBs, 0644); err != nil { if err := ioutil.WriteFile(pidFile, pidBs, 0644); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err) fmt.Fprintf(os.Stderr, "Error: %s\n", err)
// TODO: Also kill the detached process (once it is detached)
os.Exit(1) os.Exit(1)
} }
// Wait "forever" (calling test chooses when we exit with signal/Wait to // Wait "forever" (calling test chooses when we exit with signal/Wait to
// minimise coordination) // minimise coordination).
for { for {
time.Sleep(time.Hour) time.Sleep(time.Hour)
} }