From 7b44724205f71dd0ce62984eba29cf44e845d07e Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Fri, 22 Jul 2022 11:05:55 -0700 Subject: [PATCH] Fix WAL compression fragmentation test (#10402) Summary: Previously the "Fragmentation" test didn't cover fragmentation because the WAL data was compressible into trivial size. This PR changes it to use random data so the post-compression size is large enough to require fragmentation. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10402 Reviewed By: cbi42 Differential Revision: D38065596 Pulled By: ajkr fbshipit-source-id: 0d5f89ca14d33546501a74b5d4fafbadc28a46a7 --- db/log_test.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/db/log_test.cc b/db/log_test.cc index c7bc45656..444955083 100644 --- a/db/log_test.cc +++ b/db/log_test.cc @@ -960,12 +960,19 @@ TEST_P(CompressionLogTest, Fragmentation) { return; } ASSERT_OK(SetupTestEnv()); - Write("small"); - Write(BigString("medium", 50000)); - Write(BigString("large", 100000)); - ASSERT_EQ("small", Read()); - ASSERT_EQ(BigString("medium", 50000), Read()); - ASSERT_EQ(BigString("large", 100000), Read()); + Random rnd(301); + const std::vector wal_entries = { + "small", + rnd.RandomBinaryString(3 * kBlockSize / 2), // Spans into block 2 + rnd.RandomBinaryString(3 * kBlockSize), // Spans into block 5 + }; + for (const std::string& wal_entry : wal_entries) { + Write(wal_entry); + } + + for (const std::string& wal_entry : wal_entries) { + ASSERT_EQ(wal_entry, Read()); + } ASSERT_EQ("EOF", Read()); }