Files
spinifex/tests/e2e/multinode/node_recovery_test.go
T
Josh Siviour 92fa467c90 refactor(e2e/multinode): flatten spread + parallel bucket + drop phase numbers (#245)
* refactor(e2e/multinode): flatten phase 11 + parallelize bucket #1 + drop phase numbers

Split monolithic phase11_PlacementAndNATGateway (~430 lines, 8 inline
sub-steps) into 6 top-level Tests, each owning its own VPC graph via
t.Cleanup and layered setup helpers (spreadSetupVPC, spreadSetupBastion,
spreadSetupPrivateTrio, spreadSetupNATGW). The cleanup-ordering test
flips *bool latches as each explicit teardown step succeeds so the
LIFO unwind is a no-op on the success path.

Add t.Parallel() to read-only / independent Tests: ClusterHealth,
InstanceDistribution, GuestSSH, VPCNetworking. Deviates from the
mulga-siv-127 bead's bucket-#1 listing by keeping CrossNodeGateway
sequential (asserts a snapshot equality across gateways that the
parallel VPC test would break by churning instance count mid-assert)
and CrossNodeOps sequential (stops/starts trio[0], would race
GuestSSH). Both deviations documented in tests_test.go + plan doc.

Drop the bash phase numbering (phaseN_X funcs + "Phase N" log strings)
from the rest of the suite — 10 funcs renamed to runX. Phase numbers
were a port-time crutch; the Test names now describe each scenario and
phase numbers ageing into noise as bash is retired in Stage H.

* refactor(e2e/multinode): collapse spread Tests + control execution order

Two changes wedged together since they touch the same files:

1. Collapse the 6 top-level TestMultinodeSpread* Tests into a single
   TestMultinodeSpread with 6 t.Run sub-tests sharing one VPC + bastion +
   private trio + NAT GW setup chain. The 6-test split paid setup cost
   6× — bastion launch + private trio launch + NAT GW provision per Test
   pushed phase-11 wall-clock near 60min vs ~15min monolithic. Shared-
   setup layout keeps JUnit granularity (one row per sub-test) while
   restoring the monolithic budget. Setup helpers register t.Cleanup
   against the outer test so teardown runs once at the end (LIFO:
   NAT GW → trio → bastion → VPC).

2. Move the TestMultinodeSpread wrapper into tests_test.go so file-source
   order controls execution position. Previously the func lived in
   placement_nat_test.go which sorts before preflight_test.go and
   tests_test.go alphabetically — Spread ran FIRST in the sequential
   bucket, defeating Preflight's fail-fast on a sick cluster. Wrapper now
   runs after NodeRecovery so the cluster has been fully degrade-tested
   before Spread's 4-VM + NAT GW + custom-VPC graph spins up.
2026-05-21 20:53:59 +10:00

53 lines
2.3 KiB
Go

//go:build e2e
package multinode
import (
"testing"
"time"
"github.com/mulgadc/spinifex/tests/e2e/harness"
"github.com/stretchr/testify/require"
)
// runNodeRecovery is the Go port of node-recovery validation
// (run-multinode-e2e.sh:961-1037). Starts spinifex.target on node2, waits for
// NATS to reform to 2 peers, gateway to answer, spx get nodes to show 3
// Ready, and node2's gateway to answer DescribeInstanceTypes.
//
// Idempotent: if runNodeFailure didn't actually take node2 down (e.g.
// `go test -run TestMultinodeNodeRecovery` in isolation), the StartNode call
// no-ops and the assertions still hold.
func runNodeRecovery(t *testing.T, fix *Fixture) {
harness.Phase(t, "Multinode — Node Recovery")
require.GreaterOrEqualf(t, len(fix.Cluster.Nodes), 3, "node recovery requires a 3-node cluster, have %d", len(fix.Cluster.Nodes))
node2 := fix.Cluster.Nodes[1]
harness.Step(t, "start spinifex.target on %s (%s)", node2.Name, node2.Addr)
harness.StartNode(t, node2)
harness.Step(t, "wait NATS to reform to 2 peers")
fix.Cluster.WaitNATSPeers(t, 2, harness.WithTimeout(2*time.Minute), harness.WithPoll(2*time.Second))
harness.Step(t, "wait %s gateway to answer HTTPS", node2.Name)
harness.WaitNodeServiceReady(t, node2, harness.WithTimeout(60*time.Second), harness.WithPoll(2*time.Second))
// Bash (run-multinode-e2e.sh:1018) appends `|| echo ""` to swallow a
// non-zero spx exit and never checks Ready count strictly — recovery is
// gated on the gateway DescribeInstanceTypes call below, which actually
// proves end-to-end NATS routing through node2. Downgrade spx to WARN.
harness.Step(t, "spx get nodes shows %d Ready after recovery (best-effort)", len(fix.Cluster.Nodes))
out := harness.SpxGetNodesAcrossCluster(t)
harness.Detail(t, "spx_get_nodes", out)
if ready := readyNodeCount(out); ready < len(fix.Cluster.Nodes) {
t.Logf("WARN: spx get nodes shows %d Ready after recovery (want >= %d) — proceeding (bash treats this as non-fatal)\n%s",
ready, len(fix.Cluster.Nodes), out)
}
harness.Step(t, "DescribeInstanceTypes answers via %s after recovery", node2.Name)
cli := harness.AWSClientForGateway(t, fix.Env, node2)
_, err := cli.EC2.DescribeInstanceTypes(nil)
require.NoErrorf(t, err, "%s describe-instance-types after recovery", node2.Name)
}