From 770dea9325491b6e8c7b81f5601b7ae4490b15a6 Mon Sep 17 00:00:00 2001 From: sdong Date: Mon, 7 Dec 2015 18:07:01 -0800 Subject: [PATCH] Fix occasional failure of DBTest.DynamicCompactionOptions Summary: DBTest.DynamicCompactionOptions ocasionally fails during valgrind run. We sent a sleeping task to block compaction thread pool but we don't wait it to run. Test Plan: Run the test multiple times in an environment which can cause failure. Reviewers: rven, kradhakrishnan, igor, IslamAbdelRahman, anthony, yhchiang Reviewed By: yhchiang Subscribers: leveldb, dhruba Differential Revision: https://reviews.facebook.net/D51687 --- db/db_test.cc | 3 ++- util/testutil.h | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/db/db_test.cc b/db/db_test.cc index 8a495500c4..d49a2256a0 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -7704,7 +7704,7 @@ TEST_F(DBTest, DynamicCompactionOptions) { test::SleepingBackgroundTask sleeping_task_low; env_->Schedule(&test::SleepingBackgroundTask::DoSleepTask, &sleeping_task_low, Env::Priority::LOW); - + sleeping_task_low.WaitUntilSleeping(); ASSERT_EQ(NumTableFilesAtLevel(0), 0); int count = 0; Random rnd(301); @@ -7737,6 +7737,7 @@ TEST_F(DBTest, DynamicCompactionOptions) { sleeping_task_low.Reset(); env_->Schedule(&test::SleepingBackgroundTask::DoSleepTask, &sleeping_task_low, Env::Priority::LOW); + sleeping_task_low.WaitUntilSleeping(); count = 0; while (count < 64) { ASSERT_OK(Put(Key(count), RandomString(&rnd, 1024), wo)); diff --git a/util/testutil.h b/util/testutil.h index a47d5abce0..641091c822 100644 --- a/util/testutil.h +++ b/util/testutil.h @@ -306,6 +306,7 @@ class SleepingBackgroundTask { void DoSleep() { MutexLock l(&mutex_); sleeping_ = true; + bg_cv_.SignalAll(); while (should_sleep_) { bg_cv_.Wait(); } @@ -313,6 +314,12 @@ class SleepingBackgroundTask { done_with_sleep_ = true; bg_cv_.SignalAll(); } + void WaitUntilSleeping() { + MutexLock l(&mutex_); + while (!sleeping_) { + bg_cv_.Wait(); + } + } void WakeUp() { MutexLock l(&mutex_); should_sleep_ = false;