diff --git a/internal/goclusterfs/lock_commit_test.go b/internal/goclusterfs/lock_commit_test.go index c57624ae..e085df35 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 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 { + 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 end := off + chunk; end%(len(data)/4) == 0 && end < len(data) && !readAfterNow() { + return + } } done <- nil }() @@ -191,6 +212,10 @@ 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))