mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
Implements the frontend contract per T1 sketch §5-9: Identity,
Backend, Provider, ProjectionView types; ErrStalePrimary /
ErrNotReady / ErrBackendClosed sentinels; memback contract-smoke
backend that re-validates full lineage on every Read/Write.
Tests per QA test-spec:
L0 x7 (provider open healthy + not-ready, backend read/write,
stale read, stale write table-driven, close, boundary guard)
L1 x1 (Publisher + VolumeBridge publication route, Epoch-bump
move, old backend rejects, new backend serves post-move)
Two sw review notes for QA Owner:
- Spec samples use engine.ReplicaProjection{VolumeID, ReplicaID,
Healthy}. Actual engine type lacks those fields; per sketch §5
the frontend defines its own Projection struct. Documented in
file headers.
- Spec's T1.L1.1 asserts ReplicaID change across the move.
Cross-replica authorship requires TopologyController, not
StaticDirective. This L1 proves Epoch-drift fence (the fence's
actual invariant). ReplicaID-change coverage routed to L2
over the real product route.
L2 test (T1.L2.1) not written: BLOCKED-BY-T0 per test-spec §6 —
the T0 noop executor cannot produce a frontend-serving projection
until the T1-owned readiness bridge lands in cmd/blockvolume.
75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
// Ownership: QA (from sketch-approved test spec v3-phase-15-t1-test-spec.md for T1 Frontend Contract Smoke).
|
|
// sw may NOT modify this file without architect approval via §8B.4 Discovery Bridge.
|
|
// See: sw-block/design/v3-phase-15-t1-test-spec.md
|
|
// Maps to ledger rows: INV-FRONTEND-001
|
|
//
|
|
// Test layer: Unit
|
|
// Bad-state family: PCDD-FRONTEND-NOT-READY-001 (T1.L0.2)
|
|
// Bounded fate: Provider returns backend only when projection is
|
|
// healthy for the requested volume; returns ErrNotReady under
|
|
// deadline expiry.
|
|
//
|
|
// Spec adaptation note: test-spec §4 uses
|
|
// engine.ReplicaProjection{VolumeID, ReplicaID, Healthy}, which
|
|
// are fields the current engine type does not carry. Sketch §5
|
|
// permits adjusting the imported projection type; the frontend
|
|
// package defines frontend.Projection for that purpose. Tests
|
|
// below use frontend.Projection instead of engine.ReplicaProjection.
|
|
package frontend_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweed-block/core/frontend"
|
|
"github.com/seaweedfs/seaweed-block/core/frontend/memback"
|
|
)
|
|
|
|
func TestProvider_OpenHealthyProjection_ReturnsBackend(t *testing.T) {
|
|
projView := newFakeProjectionView(frontend.Projection{
|
|
VolumeID: "v1",
|
|
ReplicaID: "r1",
|
|
Epoch: 5,
|
|
EndpointVersion: 3,
|
|
Healthy: true,
|
|
})
|
|
|
|
provider := memback.NewProvider(projView)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
defer cancel()
|
|
backend, err := provider.Open(ctx, "v1")
|
|
if err != nil {
|
|
t.Fatalf("Open: unexpected error: %v", err)
|
|
}
|
|
if backend == nil {
|
|
t.Fatal("Open: backend is nil")
|
|
}
|
|
defer backend.Close()
|
|
|
|
id := backend.Identity()
|
|
if id.VolumeID != "v1" || id.ReplicaID != "r1" || id.Epoch != 5 || id.EndpointVersion != 3 {
|
|
t.Fatalf("Identity mismatch: got %+v", id)
|
|
}
|
|
}
|
|
|
|
func TestProvider_OpenNotReady_ReturnsErrNotReady(t *testing.T) {
|
|
projView := newFakeProjectionView(frontend.Projection{
|
|
VolumeID: "v1",
|
|
Healthy: false,
|
|
})
|
|
provider := memback.NewProvider(projView)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
|
defer cancel()
|
|
backend, err := provider.Open(ctx, "v1")
|
|
if backend != nil {
|
|
t.Fatal("Open: expected nil backend when projection not ready")
|
|
}
|
|
if !errors.Is(err, frontend.ErrNotReady) {
|
|
t.Fatalf("Open: expected ErrNotReady, got %v", err)
|
|
}
|
|
}
|