From 9288ecc7dcd15235e315e92ffb2c6e9e7d0016dc Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Wed, 17 Jun 2026 12:19:13 +1000 Subject: [PATCH] chore: delete no op tests + speedup e2e --- spinifex/daemon/daemon_handlers_test.go | 16 --- spinifex/daemon/daemon_test.go | 106 ------------------ .../handlers/ec2/vpc/service_nats_test.go | 12 -- tests/e2e/single/baseline_test.go | 6 +- 4 files changed, 4 insertions(+), 136 deletions(-) diff --git a/spinifex/daemon/daemon_handlers_test.go b/spinifex/daemon/daemon_handlers_test.go index 86108dbfe..48ee041ad 100644 --- a/spinifex/daemon/daemon_handlers_test.go +++ b/spinifex/daemon/daemon_handlers_test.go @@ -16,7 +16,6 @@ import ( awss3 "github.com/aws/aws-sdk-go/service/s3" "github.com/mulgadc/spinifex/spinifex/awserrors" - "github.com/mulgadc/spinifex/spinifex/config" handlers_ec2_account "github.com/mulgadc/spinifex/spinifex/handlers/ec2/account" handlers_ec2_eigw "github.com/mulgadc/spinifex/spinifex/handlers/ec2/eigw" handlers_ec2_eip "github.com/mulgadc/spinifex/spinifex/handlers/ec2/eip" @@ -1125,21 +1124,6 @@ func TestHandleEC2CreateImage_MalformedJSON(t *testing.T) { assert.Equal(t, awserrors.ErrorValidationError, errResp["Code"]) } -// --- SetConfigPath test --- - -func TestSetConfigPath(t *testing.T) { - clusterCfg := &config.ClusterConfig{ - Node: "node-1", - Nodes: map[string]config.Config{"node-1": {BaseDir: "/tmp"}}, - } - daemon, err := NewDaemon(clusterCfg) - require.NoError(t, err) - - assert.Empty(t, daemon.configPath) - daemon.SetConfigPath("/etc/spinifex/config.toml") - assert.Equal(t, "/etc/spinifex/config.toml", daemon.configPath) -} - // --- handleEC2StartStoppedInstance tests --- func TestHandleEC2StartStoppedInstance_MissingInstance(t *testing.T) { diff --git a/spinifex/daemon/daemon_test.go b/spinifex/daemon/daemon_test.go index 2b7358a46..27006f0d3 100644 --- a/spinifex/daemon/daemon_test.go +++ b/spinifex/daemon/daemon_test.go @@ -759,40 +759,6 @@ func TestDaemon_BootAllocation(t *testing.T) { assert.Equal(t, expectedMem, daemon.resourceMgr.allocatedMem) } -// TestStopInstance_Deallocation verifies that stopping an instance deallocates resources -func TestStopInstance_Deallocation(t *testing.T) { - clusterCfg := &config.ClusterConfig{ - Node: "node-1", - Nodes: map[string]config.Config{"node-1": {BaseDir: "/tmp"}}, - } - daemon, err := NewDaemon(clusterCfg) - require.NoError(t, err) - - // Setup a running instance with allocated resources - instanceId := "i-test-stop" - instanceTypeStr := getTestInstanceType(t) - instanceType := daemon.resourceMgr.instanceTypes[instanceTypeStr] - daemon.vmMgr.Insert(&vm.VM{ - ID: instanceId, - InstanceType: instanceTypeStr, - Status: vm.StateRunning, - AccountID: testAccountID, - }) - - err = daemon.resourceMgr.allocate(instanceType) - require.NoError(t, err) - assert.Greater(t, daemon.resourceMgr.allocatedVCPU, 0) - - // Call stopInstance (we can't easily wait for QMP/PID here, so we just want to see deallocate call) - // Actually stopInstance runs in goroutines and waits for PID removal. - // This might be tricky to test without heavy mocking. - - // Let's test the ResourceManager deallocate directly since we've already verified - // that stopInstance calls it in the code. - daemon.resourceMgr.deallocate(instanceType) - assert.Equal(t, 0, daemon.resourceMgr.allocatedVCPU) -} - // TestCanAllocate_CountEdgeCases tests edge cases for canAllocate with count parameter func TestCanAllocate_CountEdgeCases(t *testing.T) { t.Run("MinCount_equals_MaxCount", func(t *testing.T) { @@ -1627,78 +1593,6 @@ func TestResourceManager_ConcurrentAccess(t *testing.T) { assert.Equal(t, float64(0), rm.allocatedMem, "All memory should be deallocated") } -// TestGenerateVolumes_DeleteOnTermination_FromBlockDeviceMapping verifies that -// the deleteOnTermination flag from RunInstancesInput.BlockDeviceMappings is -// propagated to the EBSRequest on the instance's volume list. -func TestGenerateVolumes_DeleteOnTermination_FromBlockDeviceMapping(t *testing.T) { - tests := []struct { - name string - deleteOnTerminationFlag *bool - expectedFlag bool - }{ - { - name: "DeleteOnTermination=true", - deleteOnTerminationFlag: aws.Bool(true), - expectedFlag: true, - }, - { - name: "DeleteOnTermination=false", - deleteOnTerminationFlag: aws.Bool(false), - expectedFlag: false, - }, - { - name: "DeleteOnTermination=nil (defaults to true)", - deleteOnTerminationFlag: nil, - expectedFlag: true, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - // Build a RunInstancesInput with BlockDeviceMappings - input := &ec2.RunInstancesInput{ - ImageId: aws.String("vol-existing-volume"), - InstanceType: aws.String("t3.micro"), - MinCount: aws.Int64(1), - MaxCount: aws.Int64(1), - } - - if tt.deleteOnTerminationFlag != nil { - input.BlockDeviceMappings = []*ec2.BlockDeviceMapping{ - { - DeviceName: aws.String("/dev/vda"), - Ebs: &ec2.EbsBlockDevice{ - VolumeSize: aws.Int64(8), - DeleteOnTermination: tt.deleteOnTerminationFlag, - }, - }, - } - } - - // Exercise the parsing logic that GenerateVolumes uses - // Default is true (matches AWS RunInstances behavior for root volumes) - deleteOnTermination := true - if len(input.BlockDeviceMappings) > 0 { - bdm := input.BlockDeviceMappings[0] - if bdm.Ebs != nil && bdm.Ebs.DeleteOnTermination != nil { - deleteOnTermination = *bdm.Ebs.DeleteOnTermination - } - } - - assert.Equal(t, tt.expectedFlag, deleteOnTermination, - "deleteOnTermination should match expected value") - - // Verify the flag is correctly assigned to an EBSRequest - ebsReq := types.EBSRequest{ - Name: "vol-test", - Boot: true, - DeleteOnTermination: deleteOnTermination, - } - assert.Equal(t, tt.expectedFlag, ebsReq.DeleteOnTermination) - }) - } -} - // TestInstanceCleanerAdapter_DeleteVolumes_DeleteOnTermination tests that // the instanceCleanerAdapter correctly handles DeleteOnTermination for each // volume type: internal volumes (EFI, cloud-init) always go through diff --git a/spinifex/handlers/ec2/vpc/service_nats_test.go b/spinifex/handlers/ec2/vpc/service_nats_test.go index f8960c3dd..520b2225e 100644 --- a/spinifex/handlers/ec2/vpc/service_nats_test.go +++ b/spinifex/handlers/ec2/vpc/service_nats_test.go @@ -3,7 +3,6 @@ package handlers_ec2_vpc import ( "encoding/json" "testing" - "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -201,14 +200,3 @@ func TestNATSVPCService_DescribeNetworkInterfaces(t *testing.T) { require.NoError(t, err) assert.GreaterOrEqual(t, len(out.NetworkInterfaces), 1) } - -func TestNATSVPCService_Timeout(t *testing.T) { - // Create NATS connection without any subscribers — should timeout - _, nc := setupTestVPCServiceWithNC(t) - client := &NATSVPCService{natsConn: nc} - - // Production code uses a 30s timeout; just verify the constructor works - // without exercising the full round-trip. - _ = client - _ = time.Second // reference time package -} diff --git a/tests/e2e/single/baseline_test.go b/tests/e2e/single/baseline_test.go index f0f11d646..5094d2191 100644 --- a/tests/e2e/single/baseline_test.go +++ b/tests/e2e/single/baseline_test.go @@ -166,9 +166,11 @@ func runDefaultSGReachabilityBaseline(t *testing.T, fix *Fixture) { pubIP := instancePublicIP(t, fix, instanceID) harness.Detail(t, "instance", instanceID, "public_ip", pubIP) - // Poll for 30s so a slow-converging datapath would still be caught. + // Probe a short window to confirm the default-deny ACL is applied and stable. + // This overlaps guest boot, and the positive phase below still pays the full + // boot wait via trySSHReady, so a longer window buys little extra coverage. harness.Step(t, "asserting tcp/22 stays blocked under default-deny SG") - deadline := time.Now().Add(30 * time.Second) + deadline := time.Now().Add(10 * time.Second) for time.Now().Before(deadline) { require.Falsef(t, tcpReachable(pubIP, 22, 3*time.Second), "tcp/22 to %s connected with NO ingress rule — default SG must deny external traffic", pubIP)