Skip to content

Commit

Permalink
tests: fix breakage caused by the compaction threads value change (#197)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
isaac-io authored and Yuval-Ariel committed May 4, 2023
1 parent e0ed0ec commit 5d8d87a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
20 changes: 13 additions & 7 deletions db/db_compaction_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2954,14 +2954,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<test::SleepingBackgroundTask> 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_;

Expand Down Expand Up @@ -2990,8 +2992,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.
Expand All @@ -3009,6 +3011,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);
Expand Down
2 changes: 2 additions & 0 deletions db/db_range_del_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,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
Expand Down
1 change: 1 addition & 0 deletions db/deletefile_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,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
Expand Down

0 comments on commit 5d8d87a

Please sign in to comment.