- args := []string{
- os.Args[0],
- "-test.v",
- "-test.run=^TestStop$",
- "-send_uncaught_sighup=" + strconv.Itoa(i),
- }
- if subTimeout != 0 {
- args = append(args, fmt.Sprintf("-test.timeout=%v", subTimeout))
- }
- out, err := testenv.Command(t, "nohup", args...).CombinedOutput()
+ var subTimeout time.Duration
+ if deadline, ok := t.Deadline(); ok {
+ subTimeout = time.Until(deadline)
+ subTimeout -= subTimeout / 10 // Leave 10% headroom for propagating output.
+ }
+ for i := 1; i <= 2; i++ {
+ i := i
+ t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
+ t.Parallel()
+
+ // POSIX specifies that nohup writes to a file named nohup.out if standard
+ // output is a terminal. However, for an exec.Cmd, standard output is
+ // not a terminal — so we don't need to read or remove that file (and,
+ // indeed, cannot even create it if the current user is unable to write to
+ // GOROOT/src, such as when GOROOT is installed and owned by root).
+
+ args := []string{
+ os.Args[0],
+ "-test.v",
+ "-test.run=^TestStop$",
+ "-send_uncaught_sighup=" + strconv.Itoa(i),
+ }
+ if subTimeout != 0 {
+ args = append(args, fmt.Sprintf("-test.timeout=%v", subTimeout))
+ }
+ out, err := testenv.Command(t, "nohup", args...).CombinedOutput()