Files
runner/internal/pkg/process/group_windows_test.go
T
silverwind 30e600d8f6 test: speed up (#1386)
Reduce redundant fixture setup, Git subprocesses, and large data copies while preserving test coverage.

Local macOS measurements against main:

| Measurement | Before | After |
| --- | ---: | ---: |
| Git package time, median of 3 alternating runs | 4.09 s | 3.48 s (-15%) |
| Allocations across 18 action-bundle cases | 489 MiB | 251 MiB (-49%) |
| Traced Git starts per checkout table run | 234 | 175 |

Reviewed-on: https://gitea.com/gitea/runner/pulls/1386
Reviewed-by: bircni <[email protected]>
2026-11-05 07:33:17 +00:00

65 lines
1.9 KiB
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 TestGroupClosePropagatesToOrphan(t *testing.T) {
group, err := NewGroup()
require.NoError(t, err)
t.Cleanup(func() { _ = group.Close() })
cmd, ready := newTestProcess(t, "orphan", false)
require.NoError(t, cmd.Start())
require.NoError(t, group.Assign(cmd.Process))
childPID := ready()
require.NoError(t, cmd.Wait())
require.True(t, cmd.ProcessState.Exited(), "the step process should have exited on its own")
require.True(t, processAlive(childPID), "orphan should outlive its parent")
waitForExit := newProcessExitWaiter(t, childPID)
require.NoError(t, group.Close())
waitForExit()
}
// TestGroupNestsWithKiller: assigned to the group first and the step's Killer
// second, cancelling the step still kills exactly that step's tree.
func TestGroupNestsWithKiller(t *testing.T) {
group, err := NewGroup()
require.NoError(t, err)
t.Cleanup(func() { _ = group.Close() })
cmd := exec.Command("powershell.exe", "-NoProfile", "-Command", "Start-Sleep -Seconds 600")
require.NoError(t, cmd.Start())
t.Cleanup(func() { _ = cmd.Process.Kill() })
require.NoError(t, group.Assign(cmd.Process))
// Nesting must be accepted, else cancellation falls back to a single-process kill.
killer, err := NewKiller(cmd.Process)
require.NoError(t, err, "the step's job object must nest inside the group's")
defer killer.Close()
waitForExit := newProcessExitWaiter(t, cmd.Process.Pid)
require.NoError(t, killer.Kill())
waitForExit()
}
// TestGroupNilSafe covers the fallback path: when the job object cannot be
// created the caller holds a nil *Group and must still be able to use it.
func TestGroupNilSafe(t *testing.T) {
var group *Group
require.NoError(t, group.Assign(nil))
require.NoError(t, group.Close())
require.NoError(t, group.Close())
}