}
defer pr.Close()
- // Wait for "x\nx\n" to indicate readiness.
+ // Wait for "x\nx\n" to indicate almost-readiness.
buf := make([]byte, 4)
_, err = io.ReadFull(pr, buf)
if err != nil || string(buf) != "x\nx\n" {
t.Fatal("subprocess failed; output:\n", string(buf))
}
+ // The child blockers print "x\n" and then block on a lock. Receiving
+ // those bytes only indicates that the child is _about to block_. Since
+ // we don't have a way to know when it is fully blocked, sleep a bit to
+ // make us less likely to lose the race and signal before the child
+ // blocks.
+ time.Sleep(100*time.Millisecond)
+
// Send SIGQUIT.
if err := cmd.Process.Signal(syscall.SIGQUIT); err != nil {
t.Fatal("signaling subprocess: ", err)