I'm interested in making this work for recent versions of Linux and MacOS only at this time.
The problem: in tests I'm using TestMain to start a process/server that I cannot modify the behavior of by changing the source (e.g. an external Redis server). Using defers I can tell the server to exit most of the time. The problem is when one of the tests panics, testing.M.Run() does not return, which I found out the hard way, then saw this issue which confirms it is expected behavior: https://github.com/golang/go/issues/13149 I'd like to be able to clean up when "go test" exits normally or panics so that the port is freed up and the tests can be run again without manually killing orphaned processes. Q1: is there a way to exec a process from TestMain and make sure that it is killed by the OS even when a Go test panics? This must work on both Linux and MacOS. Q2: if the answer above is no, then what are some other ideas? I'm currently using an intermediate bash script to start the Redis server (rather than exec'ing Redis straight from Go). The bash script starts Redis in the background and keeps track of its PID, traps signals, then blocks on a read on stdin. stdin pipe is closed to signal to the bash script that it's done and it can clean up. Is this reasonable or am I missing a simpler approach? Any existing helper tools that already do this correctly? Thank you. Dragos H. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
