From 1861e4891bb21e21ac24cd9c2ef885747ba9b328 Mon Sep 17 00:00:00 2001 From: bowang Date: Sat, 14 May 2022 14:39:58 -0700 Subject: [PATCH] test --- util/writable_file_io_priority_test.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/util/writable_file_io_priority_test.cc b/util/writable_file_io_priority_test.cc index a2c9d32d3..f781b40f4 100644 --- a/util/writable_file_io_priority_test.cc +++ b/util/writable_file_io_priority_test.cc @@ -133,6 +133,32 @@ TEST_F(WritableFileWriterIOPriorityTest, SyncWithoutFlush) { writer_->SyncWithoutFlush(true); } +TEST_F(WritableFileWriterIOPriorityTest, SyncW) { + uint32_t kMb = static_cast(1) << 20; + EnvOptions env_options; + env_options.bytes_per_sync = kMb; + std::unique_ptr wf(new FakeWF(Env::IO_HIGH)); + std::unique_ptr writer( + new WritableFileWriter(std::move(wf), "" /* don't care */, env_options)); + Random r(301); + Status s; + std::unique_ptr large_buf(new char[10 * kMb]); + for (int i = 0; i < 1000; i++) { + int skew_limit = (i < 700) ? 10 : 15; + uint32_t num = r.Skewed(skew_limit) * 100 + r.Uniform(100); + s = writer->Append(Slice(large_buf.get(), num)); + ASSERT_OK(s); + + // Flush in a chance of 1/10. + if (r.Uniform(10) == 0) { + s = writer->Flush(); + ASSERT_OK(s); + } + } + s = writer->Close(); + ASSERT_OK(s); +} + } // namespace ROCKSDB_NAMESPACE int main(int argc, char** argv) {