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..642bdab 100644 --- a/exec_test.go +++ b/exec_test.go @@ -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) + } + }) }