From a38b6172bde7158c75ed28d552d8583fe9fdb720 Mon Sep 17 00:00:00 2001 From: Matthew Mattox Date: Mon, 16 Nov 2026 17:00:09 -0600 Subject: [PATCH 1/2] test(goclusterfs): pace the uncommitted-blocks writer on the reader TestReaderNeverSeesUncommittedBlocks required the reader to see at least 3 sizes while the writer filled 16 blocks, which depends on how the two are scheduled: with #160's narrower zeroing the writes were fast enough that the reader sometimes saw only 2, about 1 run in 20 on .68. After each block the writer now waits for a read that started after it, so the reader sees every block's size, while it keeps reading during the next block's writes. Co-Authored-By: Claude Opus 5.5 --- internal/goclusterfs/lock_commit_test.go | 31 +++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/internal/goclusterfs/lock_commit_test.go b/internal/goclusterfs/lock_commit_test.go index c57624ae..6a9c21ff 100644 --- a/internal/goclusterfs/lock_commit_test.go +++ b/internal/goclusterfs/lock_commit_test.go @@ -156,13 +156,34 @@ func TestReaderNeverSeesUncommittedBlocks(t *testing.T) { for i := range data { data[i] = byte(i/BlockSize + 1) } - done := make(chan error, 1) + // After each block, node A waits for a read that started after it, so B + // sees every block's size however the two are scheduled. B keeps reading + // while A writes the next block. + done, read, stop := make(chan error, 1), make(chan struct{}, 1), make(chan struct{}) + defer close(stop) + readAfterNow := func() bool { + select { + case <-read: + default: + } + for range 2 { + select { + case <-read: + case <-stop: + return false + } + } + return true + } go func() { for off := 0; off < len(data); off += chunk { if n, errno := fileA.Write(context.Background(), nil, data[off:off+chunk], int64(off)); errno != 0 || int(n) != chunk { done <- fmt.Errorf("write at %d: n=%d errno=%v", off, n, errno) return } + if (off+chunk)%BlockSize == 0 && !readAfterNow() { + return + } } done <- nil }() @@ -191,9 +212,13 @@ func TestReaderNeverSeesUncommittedBlocks(t *testing.T) { t.Fatalf("node B read byte %#x at offset %d (block %d), want 0 or %#x", b, off, off/BlockSize, data[off]) } } + select { + case read <- struct{}{}: + default: + } } - if len(sizes) < 3 { - t.Fatalf("node B saw the file at only %d non-empty sizes while node A wrote it", len(sizes)) + if len(sizes) < blocks { + t.Fatalf("node B saw the file at only %d non-empty sizes while node A wrote %d blocks", len(sizes), blocks) } } From 29d0b31f1aff297bdf16f228edfe2b7e8e0d79b1 Mon Sep 17 00:00:00 2001 From: Matthew Mattox Date: Mon, 16 Nov 2026 18:59:04 -0600 Subject: [PATCH 2/2] test(goclusterfs): pace at quarters instead of every block Waiting after every block made the test take 30 s under -race. Three waits, after each quarter of the file, are enough to show the reader three sizes. Co-Authored-By: Claude Opus 5.5 --- internal/goclusterfs/lock_commit_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/goclusterfs/lock_commit_test.go b/internal/goclusterfs/lock_commit_test.go index 6a9c21ff..e085df35 100644 --- a/internal/goclusterfs/lock_commit_test.go +++ b/internal/goclusterfs/lock_commit_test.go @@ -156,9 +156,9 @@ func TestReaderNeverSeesUncommittedBlocks(t *testing.T) { for i := range data { data[i] = byte(i/BlockSize + 1) } - // After each block, node A waits for a read that started after it, so B - // sees every block's size however the two are scheduled. B keeps reading - // while A writes the next block. + // After each quarter of the file, node A waits for a read that started + // after it, so B sees at least three sizes however the two are scheduled. + // B keeps reading while A writes on. done, read, stop := make(chan error, 1), make(chan struct{}, 1), make(chan struct{}) defer close(stop) readAfterNow := func() bool { @@ -181,7 +181,7 @@ func TestReaderNeverSeesUncommittedBlocks(t *testing.T) { done <- fmt.Errorf("write at %d: n=%d errno=%v", off, n, errno) return } - if (off+chunk)%BlockSize == 0 && !readAfterNow() { + if end := off + chunk; end%(len(data)/4) == 0 && end < len(data) && !readAfterNow() { return } } @@ -217,8 +217,8 @@ func TestReaderNeverSeesUncommittedBlocks(t *testing.T) { default: } } - if len(sizes) < blocks { - t.Fatalf("node B saw the file at only %d non-empty sizes while node A wrote %d blocks", len(sizes), blocks) + if len(sizes) < 3 { + t.Fatalf("node B saw the file at only %d non-empty sizes while node A wrote it", len(sizes)) } }