Skip to content

Commit c51748e

Browse files
author
Ibrahim Jarif
authored
Fix flaky TestPageBufferReader2 test (#1210)
Fixes #1197 The `TestPageBufferReader2` test would fail often because of an `off-by-1` issue. The problem can be reproduced by setting `randOffset` to the biggest number that randInt31n may return statically like: ``` //randOffset := int(rand.Int31n(int32(b.length))) randOffset := int(int32(b.length-1)) ``` This makes the problem reliably reproducible as the offset is now pointing at EOF. Thus changing the line to this should hopefully solve the problem: `randOffset := int(rand.Int31n(int32(b.length-1
1 parent eee1602 commit c51748e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

y/y_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func TestPagebufferReader2(t *testing.T) {
176176
require.Equal(t, n, 10, "length of buffer and length written should be equal")
177177
require.NoError(t, err, "unable to write bytes to buffer")
178178

179-
randOffset := int(rand.Int31n(int32(b.length)))
179+
randOffset := int(rand.Int31n(int32(b.length) - 1))
180180
randLength := int(rand.Int31n(int32(b.length - randOffset)))
181181
reader := b.NewReaderAt(randOffset)
182182
// Read randLength bytes.

0 commit comments

Comments
 (0)