From 731e55c01cae9d9b7f97dfabaac65c9605b30699 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Tue, 8 Apr 2014 14:57:00 -0700 Subject: [PATCH] Fix GetProperty() test Summary: GetProperty test is flakey. Before this diff: P8635927 After: P8635945 We need to make sure the thread is done before we destruct sleeping tasks. Otherwise, bad things happen. Test Plan: See summary Reviewers: ljin, sdong, haobo, dhruba Reviewed By: ljin CC: leveldb Differential Revision: https://reviews.facebook.net/D17595 --- db/db_test.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/db/db_test.cc b/db/db_test.cc index b97273d2e..0c728184a 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -2255,18 +2255,27 @@ TEST(DBTest, NumImmutableMemTable) { class SleepingBackgroundTask { public: - SleepingBackgroundTask() : bg_cv_(&mutex_), should_sleep_(true) {} + SleepingBackgroundTask() + : bg_cv_(&mutex_), should_sleep_(true), done_with_sleep_(false) {} void DoSleep() { MutexLock l(&mutex_); while (should_sleep_) { bg_cv_.Wait(); } + done_with_sleep_ = true; + bg_cv_.SignalAll(); } void WakeUp() { MutexLock l(&mutex_); should_sleep_ = false; bg_cv_.SignalAll(); } + void WaitUntilDone() { + MutexLock l(&mutex_); + while (!done_with_sleep_) { + bg_cv_.Wait(); + } + } static void DoSleepTask(void* arg) { reinterpret_cast(arg)->DoSleep(); @@ -2276,6 +2285,7 @@ class SleepingBackgroundTask { port::Mutex mutex_; port::CondVar bg_cv_; // Signalled when background work finishes bool should_sleep_; + bool done_with_sleep_; }; TEST(DBTest, GetProperty) { @@ -2327,6 +2337,7 @@ TEST(DBTest, GetProperty) { ASSERT_EQ(num, "0"); sleeping_task_high.WakeUp(); + sleeping_task_high.WaitUntilDone(); dbfull()->TEST_WaitForFlushMemTable(); ASSERT_OK(dbfull()->Put(writeOpt, "k4", big_value)); @@ -2337,6 +2348,7 @@ TEST(DBTest, GetProperty) { ASSERT_TRUE(dbfull()->GetProperty("rocksdb.compaction-pending", &num)); ASSERT_EQ(num, "1"); sleeping_task_low.WakeUp(); + sleeping_task_low.WaitUntilDone(); } TEST(DBTest, FLUSH) {