Skip to content

Commit

Permalink
Fix flaky TestPageBufferReader2 test (#1210)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ibrahim Jarif committed Feb 5, 2020
1 parent eee1602 commit c51748e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion y/y_test.go
Expand Up @@ -176,7 +176,7 @@ func TestPagebufferReader2(t *testing.T) {
require.Equal(t, n, 10, "length of buffer and length written should be equal")
require.NoError(t, err, "unable to write bytes to buffer")

randOffset := int(rand.Int31n(int32(b.length)))
randOffset := int(rand.Int31n(int32(b.length) - 1))
randLength := int(rand.Int31n(int32(b.length - randOffset)))
reader := b.NewReaderAt(randOffset)
// Read randLength bytes.
Expand Down

0 comments on commit c51748e

Please sign in to comment.