test: witness disjoint pre-copy phase timing and record model results

This commit is contained in:
pingqiu committed 2026-11-20 15:33:41 -08:00
1 parent fdbac0f463
commit 1bd28f7c53
2 files changed
+49 -11

No files matched your search

@@ -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)
}
})
}
+22
View File
@@ -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.