From 29de20caad366d4acfdaf5a233f72e4de0086bc5 Mon Sep 17 00:00:00 2001 From: Ibrahim Jarif Date: Wed, 5 Feb 2020 15:30:49 +0530 Subject: [PATCH] Fix flaky TestPageBufferReader2 test (#1210) Fixes https://github.com/dgraph-io/badger/issues/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 --- badger/y/y_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/badger/y/y_test.go b/badger/y/y_test.go index 168da889b..d1b963184 100644 --- a/badger/y/y_test.go +++ b/badger/y/y_test.go @@ -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.