exec: increase default wait delay

Should avoid killing Nix command whenever possible.
This commit is contained in:
Ophestra 2025-07-23 10:55:42 +09:00
parent 4787f51d84
commit e448541464
Signed by: cat
SSH Key Fingerprint: SHA256:wr6yH7sDDbUFi81k/GsIGwpM3O2QrwqYlLF26CcJa4w
3 changed files with 22 additions and 2 deletions

View File

@ -11,7 +11,7 @@ import (
)
const (
defaultWaitDelay = 15 * time.Second
defaultWaitDelay = 30 * time.Second
)
// Nix is the name of the nix program.

View File

@ -107,7 +107,7 @@ func TestNixStub(t *testing.T) {
Flag(&flagExtraExperimentalFeatures, trimFlagName(nix.ExtraExperimentalFeatures), command.StringFlag(""),
fmt.Sprintf("expects exactly %q", nix.ExperimentalFeaturesFlakes))
c.Command("true", command.UsageInternal, func([]string) error { return nil })
c.Command(nix.ValueTrue, command.UsageInternal, func([]string) error { return nil })
for _, f := range stubCommandInit {
f(c)

View File

@ -1,6 +1,7 @@
package nix_test
import (
"context"
"errors"
"os"
"os/exec"
@ -33,4 +34,23 @@ func TestNixWriteStdin(t *testing.T) {
t.Fatalf("WriteStdinCommand: error = %v, want %v", err, syscall.ENOSYS)
}
})
t.Run("exit before cancel", func(t *testing.T) {
stubNixCommand(t)
ctx := newStubContext(t.Context(), nil, os.Stdout, os.Stderr)
c, cancel := context.WithCancel(t.Context())
defer cancel()
cmd := ctx.Nix(c, "true")
if err := cmd.Start(); err != nil {
t.Fatalf("Start: error = %v", err)
}
// Cancel is skipped after exec.Cmd.Wait completes
if _, err := cmd.Process.Wait(); err != nil {
t.Fatalf("Wait: error = %v", err)
}
cancel()
if cmd.Err != nil {
t.Fatalf("Err = %v", cmd.Err)
}
})
}