From 73438c6d7bd9287a40d563772f9cd743a9611300 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Wed, 23 Jul 2025 10:55:42 +0900 Subject: [PATCH] exec: increase default wait delay Should avoid killing Nix command whenever possible. --- exec.go | 2 +- stub_test.go => exec_stub_test.go | 2 +- exec_test.go | 23 +++++++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) rename stub_test.go => exec_stub_test.go (97%) diff --git a/exec.go b/exec.go index 6973404..65b27de 100644 --- a/exec.go +++ b/exec.go @@ -11,7 +11,7 @@ import ( ) const ( - defaultWaitDelay = 15 * time.Second + defaultWaitDelay = 30 * time.Second ) // Nix is the name of the nix program. diff --git a/stub_test.go b/exec_stub_test.go similarity index 97% rename from stub_test.go rename to exec_stub_test.go index 7ef6a9d..73bea86 100644 --- a/stub_test.go +++ b/exec_stub_test.go @@ -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) diff --git a/exec_test.go b/exec_test.go index 9d2a56b..44635c0 100644 --- a/exec_test.go +++ b/exec_test.go @@ -1,14 +1,14 @@ package nix_test import ( + "context" "errors" + "gensokyo.uk/nix" "os" "os/exec" "slices" "syscall" "testing" - - "gensokyo.uk/nix" ) func TestNixWriteStdin(t *testing.T) { @@ -33,4 +33,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) + } + }) }