From 5792c3b959d5b5f2e0bd0fe5fda5eefaebae2614 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 21 Oct 2026 16:57:31 +0200 Subject: [PATCH] Keep the unit level within its bound: the counter test counts 400 not 2000, the deadline test waits 50 ms not 1 s (issue 895) Both still prove what they did: the counter test still collides every run and fails when an increment writes without its revision; the deadline test fails when the read after a failed write takes a later deadline than the ask's. --- go/cli/refusal_test.go | 6 +++--- go/state_counter_test.go | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/go/cli/refusal_test.go b/go/cli/refusal_test.go index 2adbc28..d05ec87 100644 --- a/go/cli/refusal_test.go +++ b/go/cli/refusal_test.go @@ -106,7 +106,7 @@ func TestAFailedWriteWaitsNoLongerThanTheDeadline(t *testing.T) { default: } }) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond) defer cancel() start := time.Now() _, err = Ask(ctx, socket, aLineTheSocketCannotHold()) @@ -117,7 +117,7 @@ func TestAFailedWriteWaitsNoLongerThanTheDeadline(t *testing.T) { if !errors.Is(err, os.ErrDeadlineExceeded) { t.Fatalf("the error is not the deadline: %v", err) } - if waited > 3*time.Second { - t.Fatalf("waited %s with a deadline of 1s", waited) + if waited > time.Second { + t.Fatalf("waited %s with a deadline of 50ms", waited) } } diff --git a/go/state_counter_test.go b/go/state_counter_test.go index 764a1db..fb89617 100644 --- a/go/state_counter_test.go +++ b/go/state_counter_test.go @@ -138,11 +138,11 @@ func text(t *testing.T, a map[string]any) (string, bool) { return content[0].(map[string]any)["text"].(string), isError } -// Two writers incrementing one counter a thousand times each end at two thousand: every number handed out +// Two writers incrementing one counter two hundred times each end at four hundred: every number handed out // once, none lost, each writer's numbers rising — read, then written only at the revision read. func TestTwoWritersIncrementingOneCounterLoseNoUpdate(t *testing.T) { r := &casRuntime{keys: map[string]StateEntry{}, writes: map[string]int{}} - const each = 1000 + const each = 200 // enough to collide every run (about a third of writes are lost), cheap on a slow builder got := counting(t, r, func() (any, error) { var wg sync.WaitGroup numbers := make([][]uint64, 2) @@ -179,7 +179,7 @@ func TestTwoWritersIncrementingOneCounterLoseNoUpdate(t *testing.T) { } return len(seen), nil }) - if out, isError := text(t, got); isError || out != "2000" { + if out, isError := text(t, got); isError || out != fmt.Sprint(2*each) { t.Fatalf("two writers counted %s (error: %v)", out, isError) } var final uint64 @@ -190,7 +190,7 @@ func TestTwoWritersIncrementingOneCounterLoseNoUpdate(t *testing.T) { if r.lost == 0 { t.Fatal("the two writers never collided: the test proved nothing about contention") } - t.Logf("2000 increments, %d writes lost to the other writer and tried again", r.lost) + t.Logf("%d increments, %d writes lost to the other writer and tried again", 2*each, r.lost) if r.writes["create"] != 1 || r.writes["update"] != 2*each-1 || r.writes["put"] != 0 { t.Fatalf("written by %v: one create, then updates at the revision read, never a put", r.writes) }