ci: add a test workflow (build, vet, go test -short) and harden dead-port tests

- .github/workflows/test.yml, job 'go test (linux)': on pull_request and on
  push to main; Go from go.mod; go build ./..., go vet ./..., and
  go test -short -count=1 -timeout 10m ./... with CGO_ENABLED=0. Actions are
  pinned by commit SHA, permissions are contents: read, and a new push to a
  PR cancels the older run.
- core/ops/surface_test.go: fix the two go vet warnings (resp used before
  the error check), so vet covers the whole module.
- cmd/blockvolume: a withdrawn port no longer has to answer ECONNREFUSED.
  A successful connect still fails; any other dial error passes only if the
  address can be bound again.
- core/host/volume: probe tests dial a listener they opened and closed,
  not the fixed 127.0.0.1:1.
- core/replication/component: on failure, the G5-5C and G9A catch-up tests
  log frontiers, peer status and the engine trace. Assertions and timeouts
  are unchanged.

Test files and the workflow only; no product code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-16 11:47:44 -08:00
1 parent ba3bbfe25b
commit 48db2739ec
6 files changed
+132 -20

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
name: Test
on:
pull_request:
push:
branches:
- main
permissions:
contents: read
# One run per PR (or per branch for pushes). A new push to a PR cancels the
# superseded run; runs on main are never cancelled so every merge gets a result.
concurrency:
group: test-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
test:
name: go test (linux)
runs-on: ubuntu-latest
timeout-minutes: 25
env:
# Pure-Go build: no package in the default build needs cgo, and the
# hosted runner should not depend on a C toolchain being present.
CGO_ENABLED: "0"
steps:
- name: Checkout
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- name: Go version
run: go version
- name: Build
run: go build ./...
- name: Vet
run: go vet ./...
- name: Test
run: go test -short -count=1 -timeout 10m ./...
@@ -163,13 +163,32 @@ func ingressWireClosed(t *testing.T, c net.Conn) {
}
func ingressClosedPort(t *testing.T, addr string) {
t.Helper()
if err := ingressPortReleased(addr); err != nil {
t.Fatal(err)
}
}
// ingressPortReleased returns nil once nothing listens on addr any more.
// A connect that succeeds is always a failure. A refused connect is the
// fast path. Some network stacks do not refuse promptly (a filtered or
// forwarded loopback can drop or delay the SYN, so the dial times out
// instead), so any other dial failure is accepted only if addr can be bound
// again, which proves the withdrawn listener released it.
func ingressPortReleased(addr string) error {
c, e := net.DialTimeout("tcp", addr, time.Second)
if c != nil {
if e == nil {
c.Close()
return fmt.Errorf("withdrawn endpoint %s accepted a connection", addr)
}
if !errors.Is(e, syscall.ECONNREFUSED) {
t.Fatalf("withdrawn endpoint %s accepted connection: %v", addr, e)
if errors.Is(e, syscall.ECONNREFUSED) {
return nil
}
ln, le := net.Listen("tcp", addr)
if le != nil {
return fmt.Errorf("withdrawn endpoint %s: dial failed without refusal (%v) and the address is still bound (%v)", addr, e, le)
}
_ = ln.Close()
return nil
}
// Each acquired resource is attached to this owner before the next fallible
@@ -280,12 +299,8 @@ func (o *ingressTestOwner) cleanup() error {
return
}
for _, addr := range []string{o.addr, o.dual} {
c, e := net.DialTimeout("tcp", addr, time.Second)
if c != nil {
c.Close()
}
if !errors.Is(e, syscall.ECONNREFUSED) {
o.cleanupErr = fmt.Errorf("cleanup port remains open: %s %v", addr, e)
if e := ingressPortReleased(addr); e != nil {
o.cleanupErr = fmt.Errorf("cleanup port remains open: %w", e)
return
}
}
@@ -2,6 +2,7 @@ package volume
import (
"context"
"net"
"testing"
"github.com/seaweedfs/seaweed-block/core/adapter"
@@ -74,17 +75,18 @@ func TestProductionProbeFn_RouterReturnsNil_ReturnsErr(t *testing.T) {
// this, the per-peer-adapter wiring could regress to "always pick
// the same adapter" and engine.checkReplicaID would drop events.
func TestProductionProbeFn_RouterPicksByReplicaID(t *testing.T) {
dead := closedLoopbackAddr(t)
r1Adpt := adapter.NewVolumeReplicaAdapter(fakeExecutorAdapter())
r1Adpt.OnAssignment(adapter.AssignmentInfo{
VolumeID: "vol1", ReplicaID: "r1",
Epoch: 1, EndpointVersion: 1,
DataAddr: "127.0.0.1:1", CtrlAddr: "127.0.0.1:1",
DataAddr: dead, CtrlAddr: dead,
})
r2Adpt := adapter.NewVolumeReplicaAdapter(fakeExecutorAdapter())
r2Adpt.OnAssignment(adapter.AssignmentInfo{
VolumeID: "vol1", ReplicaID: "r2",
Epoch: 1, EndpointVersion: 1,
DataAddr: "127.0.0.1:1", CtrlAddr: "127.0.0.1:1",
DataAddr: dead, CtrlAddr: dead,
})
router := keyedRouter(map[string]*adapter.VolumeReplicaAdapter{
@@ -93,10 +95,10 @@ func TestProductionProbeFn_RouterPicksByReplicaID(t *testing.T) {
})
fn := ProductionProbeFn(router)
// Probe transport will fail for both (unreachable :1) — that's
// Probe transport will fail for both (closed listener) — that's
// fine; we're verifying routing happened, not transport success.
peer1 := newPeerForWiringTest(t, "r1", "127.0.0.1:1", "127.0.0.1:1", 1, 1)
peer2 := newPeerForWiringTest(t, "r2", "127.0.0.1:1", "127.0.0.1:1", 1, 1)
peer1 := newPeerForWiringTest(t, "r1", dead, dead, 1, 1)
peer2 := newPeerForWiringTest(t, "r2", dead, dead, 1, 1)
if err := fn(context.Background(), peer1); err == nil {
t.Fatal("expected probe transport failure")
@@ -118,6 +120,19 @@ func TestProductionProbeFn_RouterPicksByReplicaID(t *testing.T) {
}
}
// closedLoopbackAddr returns a loopback address whose listener has been
// closed, so nothing accepts on it for the rest of the test.
func closedLoopbackAddr(t *testing.T) string {
t.Helper()
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
addr := ln.Addr().String()
_ = ln.Close()
return addr
}
// newPeerForWiringTest builds a real *ReplicaPeer with valid lineage
// pointing at the given (data, ctrl) addresses. The probeFn will dial
// those addresses; tests that don't want real wire activity should
@@ -156,16 +171,19 @@ func TestProductionProbeFn_TransportFailure_ReturnsErr(t *testing.T) {
adpt := adapter.NewVolumeReplicaAdapter(fakeExecutorAdapter())
// Prime the adapter with an assignment so OnProbeResult has a
// known peer to associate with.
dead := closedLoopbackAddr(t)
adpt.OnAssignment(adapter.AssignmentInfo{
VolumeID: "vol1", ReplicaID: "r1",
Epoch: 1, EndpointVersion: 1,
DataAddr: "127.0.0.1:1", CtrlAddr: "127.0.0.1:1",
DataAddr: dead, CtrlAddr: dead,
})
fn := ProductionProbeFn(staticRouter(adpt))
// Use a definitely-unreachable address. 127.0.0.1:1 is reserved
// (TCPMUX) and almost always closed; the dial will fail fast.
peer := newPeerForWiringTest(t, "r1", "127.0.0.1:1", "127.0.0.1:1", 1, 1)
// Use an address whose listener this test opened and closed, rather
// than a well-known port that the host may filter or forward. The
// probe dial is bounded, so it fails either at once (refused) or at
// the dial timeout; it can never succeed.
peer := newPeerForWiringTest(t, "r1", dead, dead, 1, 1)
err := fn(context.Background(), peer)
if err == nil {
+8 -2
View File
@@ -55,7 +55,10 @@ func TestSurfaceIndex_WordingIsSingleNode(t *testing.T) {
url, cleanup := newTestServer(t, NewState())
defer cleanup()
resp, _ := http.Get(url + "/")
resp, err := http.Get(url + "/")
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
text := strings.ToLower(string(body))
@@ -105,7 +108,10 @@ func TestDiagnose_OnlyReadsLowerTruth(t *testing.T) {
url, cleanup := newTestServer(t, NewState())
defer cleanup()
resp, _ := http.Get(url + "/diagnose")
resp, err := http.Get(url + "/diagnose")
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
var body diagnoseBody
_ = json.NewDecoder(resp.Body).Decode(&body)
@@ -172,6 +172,27 @@ func writeOneBlock(t *testing.T, c *Cluster, lba uint32, fillByte byte) {
}
}
// logRecoveryStateOnFailure records the recovery state that a failed
// convergence wait leaves behind: both frontiers, the peer status, and the
// replica-0 engine projection and trace. WaitForConverge only reports which
// LBAs differ; this shows where the probe -> catch-up loop stopped.
// Registered after Start, it runs before the cluster's own cleanups.
func logRecoveryStateOnFailure(t *testing.T, c *Cluster) {
t.Helper()
t.Cleanup(func() {
if !t.Failed() {
return
}
_, _, pH := c.primary.Store.Boundaries()
_, _, rH := c.Replica(0).Store.Boundaries()
t.Logf("on failure: primary H=%d replica H=%d peers=%+v", pH, rH, c.primary.RepVol.PeerStatuses())
if a := c.Adapter(0); a != nil {
t.Logf("on failure: projection=%+v", a.Projection())
t.Logf("on failure: trace=%+v", a.Trace())
}
})
}
// markReplicaDegradedAfterFailedShip waits up to a short bounded
// deadline for the peer state to reach ReplicaDegraded after a ship
// failure. The peer transitions in ShipEntry's error path
@@ -231,6 +252,7 @@ func TestG5_5C_RestartCatchUp_Convergence(t *testing.T) {
WithLiveShip().
WithEngineDrivenRecovery().
Start()
logRecoveryStateOnFailure(t, c)
// Step 1: admit replica + initial probe → engine Healthy.
drivePeerAdmit(t, c)
@@ -14,6 +14,7 @@ func TestG9A_BestEffortWriteStillFeedsLaggingReplicaRecovery(t *testing.T) {
WithLiveShip().
WithEngineDrivenRecovery().
Start()
logRecoveryStateOnFailure(t, c)
c.primary.RepVol.SetDurabilityMode(replication.DurabilityBestEffort)
drivePeerAdmit(t, c)