Skip to content

Commit 84fe3de

Browse files
authored
integration: reduce TestAutoApproveMultiNetwork matrix to 3 tests (#2815)
1 parent 450a7b1 commit 84fe3de

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

integration/hsic/hsic.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,26 +1232,26 @@ func (h *HeadscaleInContainer) writePolicy(pol *policyv2.Policy) error {
12321232
}
12331233

12341234
func (h *HeadscaleInContainer) PID() (int, error) {
1235-
cmd := []string{"bash", "-c", `ps aux | grep headscale | grep -v grep | awk '{print $2}'`}
1236-
output, err := h.Execute(cmd)
1235+
// Use pidof to find the headscale process, which is more reliable than grep
1236+
// as it only looks for the actual binary name, not processes that contain
1237+
// "headscale" in their command line (like the dlv debugger).
1238+
output, err := h.Execute([]string{"pidof", "headscale"})
12371239
if err != nil {
1238-
return 0, fmt.Errorf("failed to execute command: %w", err)
1240+
// pidof returns exit code 1 when no process is found
1241+
return 0, os.ErrNotExist
12391242
}
12401243

1241-
lines := strings.TrimSpace(output)
1242-
if lines == "" {
1243-
return 0, os.ErrNotExist // No output means no process found
1244+
// pidof returns space-separated PIDs on a single line
1245+
pidStrs := strings.Fields(strings.TrimSpace(output))
1246+
if len(pidStrs) == 0 {
1247+
return 0, os.ErrNotExist
12441248
}
12451249

1246-
pids := make([]int, 0, len(lines))
1247-
for _, line := range strings.Split(lines, "\n") {
1248-
line = strings.TrimSpace(line)
1249-
if line == "" {
1250-
continue
1251-
}
1252-
pidInt, err := strconv.Atoi(line)
1250+
pids := make([]int, 0, len(pidStrs))
1251+
for _, pidStr := range pidStrs {
1252+
pidInt, err := strconv.Atoi(pidStr)
12531253
if err != nil {
1254-
return 0, fmt.Errorf("parsing PID: %w", err)
1254+
return 0, fmt.Errorf("parsing PID %q: %w", pidStr, err)
12551255
}
12561256
// We dont care about the root pid for the container
12571257
if pidInt == 1 {
@@ -1266,7 +1266,9 @@ func (h *HeadscaleInContainer) PID() (int, error) {
12661266
case 1:
12671267
return pids[0], nil
12681268
default:
1269-
return 0, errors.New("multiple headscale processes running")
1269+
// If we still have multiple PIDs, return the first one as a fallback
1270+
// This can happen in edge cases during startup/shutdown
1271+
return pids[0], nil
12701272
}
12711273
}
12721274

integration/route_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/stretchr/testify/assert"
2525
"github.com/stretchr/testify/require"
2626
xmaps "golang.org/x/exp/maps"
27+
"tailscale.com/envknob"
2728
"tailscale.com/ipn/ipnstate"
2829
"tailscale.com/net/tsaddr"
2930
"tailscale.com/tailcfg"
@@ -2215,11 +2216,31 @@ func TestAutoApproveMultiNetwork(t *testing.T) {
22152216
},
22162217
}
22172218

2219+
// Check if we should run the full matrix of tests
2220+
// By default, we only run a minimal subset to avoid overwhelming Docker/disk
2221+
// Set HEADSCALE_INTEGRATION_FULL_MATRIX=1 to run all combinations
2222+
fullMatrix := envknob.Bool("HEADSCALE_INTEGRATION_FULL_MATRIX")
2223+
2224+
// Minimal test set: 3 tests covering all key dimensions
2225+
// - Both auth methods (authkey, webauth)
2226+
// - All 3 approver types (tag, user, group)
2227+
// - Both policy modes (database, file)
2228+
// - Both advertiseDuringUp values (true, false)
2229+
minimalTestSet := map[string]bool{
2230+
"authkey-tag-advertiseduringup-false-pol-database": true, // authkey + database + tag + false
2231+
"webauth-user-advertiseduringup-true-pol-file": true, // webauth + file + user + true
2232+
"authkey-group-advertiseduringup-false-pol-file": true, // authkey + file + group + false
2233+
}
2234+
22182235
for _, tt := range tests {
22192236
for _, polMode := range []types.PolicyMode{types.PolicyModeDB, types.PolicyModeFile} {
22202237
for _, advertiseDuringUp := range []bool{false, true} {
22212238
name := fmt.Sprintf("%s-advertiseduringup-%t-pol-%s", tt.name, advertiseDuringUp, polMode)
22222239
t.Run(name, func(t *testing.T) {
2240+
// Skip tests not in minimal set unless full matrix is enabled
2241+
if !fullMatrix && !minimalTestSet[name] {
2242+
t.Skip("Skipping to reduce test matrix size. Set HEADSCALE_INTEGRATION_FULL_MATRIX=1 to run all tests.")
2243+
}
22232244
scenario, err := NewScenario(tt.spec)
22242245
require.NoErrorf(t, err, "failed to create scenario: %s", err)
22252246
defer scenario.ShutdownAssertNoPanics(t)

0 commit comments

Comments
 (0)