mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-06 15:20:29 +00:00
The test context is cancelled when the test ends, so anything still holding it stops instead of leaking into the next test. Uses inside `t.Cleanup`, `defer` and `go func` blocks are left alone, as the context is already cancelled there. Stacked on https://gitea.com/gitea/runner/pulls/1305. Assisted-by: Codet Co-authored-by: bircni <[email protected]> Reviewed-on: https://gitea.com/gitea/runner/pulls/1306 Reviewed-by: bircni <[email protected]>
36 lines
867 B
Go
36 lines
867 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package process
|
|
|
|
import (
|
|
"os/exec"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNewTreeKillConfiguresCommand(t *testing.T) {
|
|
cmd := exec.CommandContext(t.Context(), "sleep", "1")
|
|
tk := NewTreeKill(cmd)
|
|
|
|
require.NotNil(t, tk)
|
|
require.NotNil(t, cmd.Cancel)
|
|
require.Equal(t, treeKillWaitDelay, cmd.WaitDelay)
|
|
require.NoError(t, cmd.Cancel())
|
|
}
|
|
|
|
func TestTreeKillCaptureStoresKiller(t *testing.T) {
|
|
cmd := exec.CommandContext(t.Context(), "sleep", "10")
|
|
cmd.SysProcAttr = SysProcAttr("", false)
|
|
tk := NewTreeKill(cmd)
|
|
require.NoError(t, cmd.Start())
|
|
defer func() { _ = cmd.Wait() }()
|
|
|
|
killer, err := tk.Capture(cmd.Process)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, killer)
|
|
require.NoError(t, cmd.Cancel())
|
|
require.NoError(t, killer.Close())
|
|
}
|