From c9cddedb0bbfe1d70c014745d7ec47c0b38d3511 Mon Sep 17 00:00:00 2001 From: Isaac Garzon Date: Sun, 23 Oct 2022 13:34:41 +0300 Subject: [PATCH] tests: fix breakage caused by the compaction threads value change (#197) In #194 the default value for background compaction threads was changed to 8 (from 1). This caused some tests to fail, but they were fixed. Alas, the fixes seems to not be complete, as under stress some tests still fail. Make it so the tests are truly fixed now. This can be checked by running them in a loop with the machine overloaded: ``` $ while ./db_compaction_test --gtest_filter=DBCompactionTestWithParam/DBCompactionTestWithParam.PartialCompactionFailure/1; do sleep 1; done ``` And ``` $ while ./deletefile_test --gtest_filter=DeleteFileTest.BackgroundPurgeCopyOptions; do sleep 1; done ``` --- db/db_compaction_test.cc | 20 +++++++++++++------- db/db_range_del_test.cc | 2 ++ db/deletefile_test.cc | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/db/db_compaction_test.cc b/db/db_compaction_test.cc index 065384a8a3..26708f9390 100644 --- a/db/db_compaction_test.cc +++ b/db/db_compaction_test.cc @@ -2848,14 +2848,16 @@ TEST_P(DBCompactionTestWithParam, PartialCompactionFailure) { options.max_bytes_for_level_multiplier = 2; options.compression = kNoCompression; options.max_subcompactions = max_subcompactions_; - options.max_background_compactions = 1; env_->SetBackgroundThreads(1, Env::HIGH); - env_->SetBackgroundThreads(1, Env::LOW); // stop the compaction thread until we simulate the file creation failure. - test::SleepingBackgroundTask sleeping_task_low; - env_->Schedule(&test::SleepingBackgroundTask::DoSleepTask, &sleeping_task_low, - Env::Priority::LOW); + std::vector sleeping_task_low( + std::max(1, env_->GetBackgroundThreads(Env::Priority::LOW))); + for (auto& sleeping_task : sleeping_task_low) { + env_->Schedule(&test::SleepingBackgroundTask::DoSleepTask, &sleeping_task, + Env::Priority::LOW); + sleeping_task.WaitUntilSleeping(); + } options.env = env_; @@ -2885,8 +2887,8 @@ TEST_P(DBCompactionTestWithParam, PartialCompactionFailure) { // Fail the first file creation. env_->non_writable_count_ = 1; - sleeping_task_low.WakeUp(); - sleeping_task_low.WaitUntilDone(); + sleeping_task_low[0].WakeUp(); + sleeping_task_low[0].WaitUntilDone(); // Expect compaction to fail here as one file will fail its // creation. @@ -2904,6 +2906,10 @@ TEST_P(DBCompactionTestWithParam, PartialCompactionFailure) { } env_->non_writable_count_ = 0; + for (size_t i = 1; i < sleeping_task_low.size(); ++i) { + sleeping_task_low[i].WakeUp(); + sleeping_task_low[i].WaitUntilDone(); + } // Make sure RocksDB will not get into corrupted state. Reopen(options); diff --git a/db/db_range_del_test.cc b/db/db_range_del_test.cc index 8451143392..40605ac05c 100644 --- a/db/db_range_del_test.cc +++ b/db/db_range_del_test.cc @@ -638,6 +638,8 @@ TEST_F(DBRangeDelTest, TableEvictedDuringScan) { bbto.cache_index_and_filter_blocks = true; bbto.block_cache = NewLRUCache(8 << 20); opts.table_factory.reset(NewBlockBasedTableFactory(bbto)); + opts.max_background_compactions = -1; + env_->SetBackgroundThreads(1, Env::Priority::LOW); DestroyAndReopen(opts); // Hold a snapshot so range deletions can't become obsolete during compaction diff --git a/db/deletefile_test.cc b/db/deletefile_test.cc index 012f30b4ed..f90075aaca 100644 --- a/db/deletefile_test.cc +++ b/db/deletefile_test.cc @@ -419,6 +419,7 @@ TEST_F(DeleteFileTest, BackgroundPurgeCopyOptions) { for (auto& sleeping_task : sleeping_task_after) { env_->Schedule(&test::SleepingBackgroundTask::DoSleepTask, &sleeping_task, Env::Priority::LOW); + sleeping_task.WaitUntilSleeping(); } // Make sure all background purges are executed