mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +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>
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package component
|
|
|
|
import "testing"
|
|
|
|
// RunMatrix runs the given scenario against each substrate factory.
|
|
// Both rows are gating; smartwal is sign-bearing per round-22.
|
|
//
|
|
// Authoring shape:
|
|
//
|
|
// 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)
|
|
// })
|
|
//
|
|
// The cluster is fresh per substrate row; t.Cleanup handles
|
|
// teardown automatically.
|
|
func RunMatrix(t *testing.T, scenario func(t *testing.T, c *Cluster)) {
|
|
t.Helper()
|
|
t.Run("smartwal", func(t *testing.T) {
|
|
scenario(t, NewCluster(t, Smartwal))
|
|
})
|
|
t.Run("walstore", func(t *testing.T) {
|
|
scenario(t, NewCluster(t, Walstore))
|
|
})
|
|
}
|
|
|
|
// RunSubstrate runs the scenario against one named substrate. Useful
|
|
// when a scenario only makes sense against a specific substrate
|
|
// (e.g., a wal_replay-specific behavior pin) — most scenarios
|
|
// should use RunMatrix instead.
|
|
func RunSubstrate(t *testing.T, name string, factory SubstrateFactory, scenario func(t *testing.T, c *Cluster)) {
|
|
t.Helper()
|
|
t.Run(name, func(t *testing.T) {
|
|
scenario(t, NewCluster(t, factory))
|
|
})
|
|
}
|