From 1bd28f7c53e4b9d3d6fce5fe6da79880bb51c668 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 15:33:41 -0800 Subject: [PATCH] test: witness disjoint pre-copy phase timing and record model results --- .../chunk_precopy_fixed_commit_test.go | 38 +++++++++++++------ seaweed-block/docs/spec/README.md | 22 +++++++++++ 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/seaweed-block/core/storage/chunk_precopy_fixed_commit_test.go b/seaweed-block/core/storage/chunk_precopy_fixed_commit_test.go index be6cdccf54..e75b81645d 100644 --- a/seaweed-block/core/storage/chunk_precopy_fixed_commit_test.go +++ b/seaweed-block/core/storage/chunk_precopy_fixed_commit_test.go @@ -5,6 +5,7 @@ import ( "context" "errors" "testing" + "testing/synctest" "time" ) @@ -142,6 +143,7 @@ func TestPrecopyFixedExceptionFinishUsesDeclaredFreeze(t *testing.T) { type precopyTimedHeadRemote struct { *fakeChunkRemote casDelay, readDelay time.Duration + beforeRead func() } func (r *precopyTimedHeadRemote) CASHead(ctx context.Context, v chunkHeadVersion, h chunkHead) (uint64, error) { @@ -155,6 +157,9 @@ func (r *precopyTimedHeadRemote) CASHead(ctx context.Context, v chunkHeadVersion return r.fakeChunkRemote.CASHead(ctx, v, h) } func (r *precopyTimedHeadRemote) GetHead(ctx context.Context) (chunkHead, error) { + if r.beforeRead != nil { + r.beforeRead() + } timer := time.NewTimer(r.readDelay) defer timer.Stop() select { @@ -165,15 +170,26 @@ func (r *precopyTimedHeadRemote) GetHead(ctx context.Context) (chunkHead, error) return r.fakeChunkRemote.GetHead(ctx) } func TestPrecopyFixedPartsMeasureCASAndReadbackSeparately(t *testing.T) { - r := &precopyTimedHeadRemote{fakeChunkRemote: newFakeChunkRemote(), casDelay: 15 * time.Millisecond, readDelay: 25 * time.Millisecond} - var st chunkCutStats - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - _, err := casAndConfirmChunkHeadMeasured(ctx, r, chunkHeadVersion{}, chunkHead{Epoch: 1, Holder: "owner", Chunks: map[uint64]chunkRef{}}, &st) - if err != nil { - t.Fatal(err) - } - if time.Duration(st.CASWriteNs) < r.casDelay || time.Duration(st.HeadReadbackNs) < r.readDelay { - t.Fatalf("missing or overlapping operation timing: %+v", st) - } + // The bubble's virtual clock advances only during the two blocked phases. + // Exact phase attribution is independent of host scheduling or elapsed limits. + synctest.Test(t, func(t *testing.T) { + r := &precopyTimedHeadRemote{fakeChunkRemote: newFakeChunkRemote(), casDelay: 15 * time.Millisecond, readDelay: 25 * time.Millisecond} + var st chunkCutStats + readEntered := false + r.beforeRead = func() { + readEntered = true + if time.Duration(st.CASWriteNs) != r.casDelay || st.HeadReadbackNs != 0 { + t.Fatalf("CAS must be settled before readback starts: %+v", st) + } + } + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + _, err := casAndConfirmChunkHeadMeasured(ctx, r, chunkHeadVersion{}, chunkHead{Epoch: 1, Holder: "owner", Chunks: map[uint64]chunkRef{}}, &st) + if err != nil { + t.Fatal(err) + } + if !readEntered || time.Duration(st.CASWriteNs) != r.casDelay || time.Duration(st.HeadReadbackNs) != r.readDelay { + t.Fatalf("overlapping or missing phase attribution: %+v readEntered=%t", st, readEntered) + } + }) } diff --git a/seaweed-block/docs/spec/README.md b/seaweed-block/docs/spec/README.md index 254f474f92..6f9709b3c4 100644 --- a/seaweed-block/docs/spec/README.md +++ b/seaweed-block/docs/spec/README.md @@ -340,3 +340,25 @@ allowance, small non-improving tail, declared freeze and the five-second ceiling `PrecopyFixedAdmission.cfg` is the positive configuration; `_no_tail`, `_no_stall` and `_no_cap` must violate `SafeCommit`. It does not model publication/data safety or physical latency; those remain separate checks. + + +### PrecopyFixedAdmission checked configurations + +Recorded local run, 2026-11-20 22:30 UTC, using the v1.7.4 tools distribution (TLC 2.19) +(`tla2tools.jar` SHA-256 +`936a262061c914694dfd669a543be24573c45d5aa0ff20a8b96b23d01e050e88`), +from `docs/spec`: + +```sh +java -cp /path/to/tla2tools.jar tla2sany.SANY PrecopyFixedAdmission.tla +java -cp /path/to/tla2tools.jar tlc2.TLC -deadlock -config cfg/PrecopyFixedAdmission.cfg PrecopyFixedAdmission +``` + +SANY exited 0. The positive configuration exited 0: 11,240 generated states, +2,856 distinct, queue empty, complete depth 6. With the same command and the +respective `cfg/PrecopyFixedAdmission_no_*.cfg`, each negative exited 12 with +`SafeCommit` violated: `no_tail` (266 generated / 262 distinct, depth 3), +`no_stall` (44 / 41, depth 2), `no_cap` (546 / 517, depth 3). +These are the original local finite-state runs for this model, not a new run +for the documentation update. The bounds and exclusions above still apply; +this does not establish physical latency, publication safety or train qualification.