diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-15 15:35:19 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-19 09:34:29 +0300 |
commit | 4971157a804b81edad655ff6f44377f2b288579c (patch) | |
tree | d9fe49d14a7baa8e2c96604044dc206a25045f34 | |
parent | a454dd8c911101edb4d1d7b8218301584ea199e7 (diff) |
command: Fix weird test setup
One of our tests verifies that we can kill commands spawned via our
`command` package by cancelling the context. The setup of this test does
not make a whole lot of sense though:
- We pass an `exec.Cmd` to `New()` that already has an explicit
context set by using `CommandContext()`. So even if the `command`
package failed to correctly reap the child, the Go runtime would
already ensure for us that the command got killed.
- We cancel the context in a separate Goroutine without much of a
point.
Fix these issues by passing a non-contextualized command to `New()` and
by cancelling the context synchronously.
-rw-r--r-- | internal/command/command_test.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/internal/command/command_test.go b/internal/command/command_test.go index c3c7b85e9..397b32456 100644 --- a/internal/command/command_test.go +++ b/internal/command/command_test.go @@ -194,11 +194,11 @@ func TestCommand_Wait_contextCancellationKillsCommand(t *testing.T) { ctx, cancel := context.WithCancel(testhelper.Context(t)) - cmd, err := New(ctx, exec.CommandContext(ctx, "sleep", "1h")) + cmd, err := New(ctx, exec.Command("sleep", "1h")) require.NoError(t, err) // Cancel the command early. - go cancel() + cancel() err = cmd.Wait() require.Error(t, err) |