mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
QA-requested (round-39): build a component test framework so QA can author T4c-follow-up + T4d scenarios in ~20-30 lines without re-deriving cluster setup boilerplate. Lands `core/replication/component/` package with: - Cluster builder: NewCluster(t, factory).WithReplicas(n).Start() → fully wired primary + N replicas over real localhost TCP using production code paths (BlockStore + ReplicaListener + BlockExecutor) - RunMatrix(t, scenario): runs the scenario across smartwal + walstore; both substrates gate per round-22 sign-bearing discipline - RunSubstrate(t, name, factory, scenario): single-substrate runner for substrate-specific pins - Write/sync primitives: PrimaryWrite, PrimaryWriteN, PrimarySync, ReplicaApply (for setting up pre-existing replica state) - Recovery primitives: CatchUpReplica, ProbeReplica - Fault injection: KillReplicaListener, SeverConnection - Convergence assertions: WaitForConverge, AssertReplicaConverged - Mode-label assertions: AssertSawRecoveryMode with ExpectAnyMode / ExpectWALReplay / ExpectStateConvergence constants - Log capture: tees log.Default writer into per-test buffer so mode- label assertions don't need stderr parsing - Mode-constant init-time pin: panics if ExpectWALReplay / ExpectStateConvergence drift from storage.RecoveryMode* values 7 demo scenarios in cluster_test.go double as smoke for the framework + copy-paste templates for QA: - TestComponent_HappyCatchUp — simplest scenario shape - TestComponent_GapExceedsRetention_Recycled — substrate fault wrap pattern (recycledScanStub demonstrates ScanLBAs override for ErrWALRecycled injection) - TestComponent_ProbeHappy — probe wire smoke across substrates - TestComponent_TwoReplicas_BothConverge — multi-replica fan-out - TestComponent_PartialReplicaThenCatchUp — ReplicaApply for pre-existing partial state setup - TestComponent_RecoveryModeLabel_Walstore — per-substrate label pin (wal_replay) - TestComponent_RecoveryModeLabel_Smartwal — per-substrate label pin (state_convergence) - TestComponent_ModeConstantsStable — drift fence Authoring guide: sw-block/design/v3-phase-15-component-test-guide.md documents the API + common patterns + extension discipline. Aim: ~20-30 lines per new scenario. Forward-carry items (sw will add when needed): - WithPrimaryStorageWrap(wrap) option — substrate fault injection at the executor layer (today the wrap pattern only works at the storage layer; substrate-level executor-test integration needs the option) - WithEngineDrivenRecovery() option — when T4d lands the ReplicationVolume↔adapter wiring, the framework gains the engine- driven recovery flow as an opt-in mode go test ./... -count=1 → all 22 packages green (component is the new package). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
53 lines
2.3 KiB
Go
53 lines
2.3 KiB
Go
// Package component provides a reusable cluster-style harness for
|
|
// authoring V3 replication scenario tests. Sits between unit tests
|
|
// (engine/transport-only, in-process types) and L3 m01 hardware
|
|
// runs (real binaries over real network).
|
|
//
|
|
// What it gives you:
|
|
//
|
|
// - A Cluster type that owns one Primary + N Replicas wired over
|
|
// real localhost TCP using the actual production code paths
|
|
// (BlockStore + ReplicaListener + BlockExecutor).
|
|
// - A substrate matrix runner — every scenario runs against
|
|
// smartwal AND walstore, both gating per round-22.
|
|
// - Network fault primitives: KillReplicaConnection / SeverTransport /
|
|
// RestoreTransport — for catch-up + degraded scenarios that L1
|
|
// unit tests can't reach.
|
|
// - Convergence + mode-label assertion helpers — the standard
|
|
// "did the replica catch up byte-exact + did the recovery_mode
|
|
// label surface" checks every T4c scenario needs.
|
|
// - Log capture so scenarios can assert on observability surfaces
|
|
// (recovery_mode label, failure reasons, etc.) without parsing
|
|
// stderr.
|
|
//
|
|
// Authoring shape (target: ~20-30 lines per scenario):
|
|
//
|
|
// func TestT4c_MyScenario(t *testing.T) {
|
|
// component.RunMatrix(t, func(t *testing.T, c *component.Cluster) {
|
|
// c.WithReplicas(1).Start()
|
|
// c.PrimaryWriteN(20)
|
|
// c.PrimarySync()
|
|
// c.CatchUpReplica(0)
|
|
// c.AssertReplicaConverged(0)
|
|
// c.AssertSawRecoveryMode(0, component.ExpectAnyMode)
|
|
// })
|
|
// }
|
|
//
|
|
// What it does NOT do:
|
|
//
|
|
// - Spin up subprocess binaries (cmd/sparrow). For full-binary
|
|
// subprocess testing, write a wrapper around os/exec; the
|
|
// component framework's API can be retargeted by swapping the
|
|
// Cluster impl.
|
|
// - Drive engine→adapter→executor recovery flows. Today
|
|
// ReplicationVolume bypasses the adapter; component scenarios
|
|
// drive catch-up directly via executor.StartCatchUp until the
|
|
// engine→adapter→executor wiring lands (forward-carry to T4d).
|
|
//
|
|
// Substrate matrix: smartwal is sign-bearing; walstore is the
|
|
// second matrix row. Both are gating in this harness — there is no
|
|
// "non-gating" demote; if walstore regresses, the test fails
|
|
// honestly. See `core/replication/l2_integration_test.go` for the
|
|
// QA round on this discipline.
|
|
package component
|