Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion internal/goclusterfs/lock_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}()
Expand Down Expand Up @@ -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))
Expand Down
Loading