From 778f2260b167ed0d5a6207c982ced40f2d670ba6 Mon Sep 17 00:00:00 2001 From: James Blair Date: Sat, 19 Aug 2023 21:41:18 +1200 Subject: [PATCH] tests: Backport deflake for TestPageWriterRandom The PageWriter has cache buffer so that it doesn't call the Writer until the cache is almost full. Since the data's length is random, the pending bytes should be always less than cache buffer size, instead of page size. Signed-off-by: James Blair --- pkg/ioutil/pagewriter_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/ioutil/pagewriter_test.go b/pkg/ioutil/pagewriter_test.go index d3b4343cb..305bc6320 100644 --- a/pkg/ioutil/pagewriter_test.go +++ b/pkg/ioutil/pagewriter_test.go @@ -37,8 +37,8 @@ func TestPageWriterRandom(t *testing.T) { if cw.writeBytes > n { t.Fatalf("wrote %d bytes to io.Writer, but only wrote %d bytes", cw.writeBytes, n) } - if n-cw.writeBytes > pageBytes { - t.Fatalf("got %d bytes pending, expected less than %d bytes", n-cw.writeBytes, pageBytes) + if maxPendingBytes := pageBytes + defaultBufferBytes; n-cw.writeBytes > maxPendingBytes { + t.Fatalf("got %d bytes pending, expected less than %d bytes", n-cw.writeBytes, maxPendingBytes) } t.Logf("total writes: %d", cw.writes) t.Logf("total write bytes: %d (of %d)", cw.writeBytes, n)