mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-26 16:30:56 +00:00
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
This commit is contained in:
parent
34455deb06
commit
731e55c01c
|
@ -2255,18 +2255,27 @@ TEST(DBTest, NumImmutableMemTable) {
|
||||||
|
|
||||||
class SleepingBackgroundTask {
|
class SleepingBackgroundTask {
|
||||||
public:
|
public:
|
||||||
SleepingBackgroundTask() : bg_cv_(&mutex_), should_sleep_(true) {}
|
SleepingBackgroundTask()
|
||||||
|
: bg_cv_(&mutex_), should_sleep_(true), done_with_sleep_(false) {}
|
||||||
void DoSleep() {
|
void DoSleep() {
|
||||||
MutexLock l(&mutex_);
|
MutexLock l(&mutex_);
|
||||||
while (should_sleep_) {
|
while (should_sleep_) {
|
||||||
bg_cv_.Wait();
|
bg_cv_.Wait();
|
||||||
}
|
}
|
||||||
|
done_with_sleep_ = true;
|
||||||
|
bg_cv_.SignalAll();
|
||||||
}
|
}
|
||||||
void WakeUp() {
|
void WakeUp() {
|
||||||
MutexLock l(&mutex_);
|
MutexLock l(&mutex_);
|
||||||
should_sleep_ = false;
|
should_sleep_ = false;
|
||||||
bg_cv_.SignalAll();
|
bg_cv_.SignalAll();
|
||||||
}
|
}
|
||||||
|
void WaitUntilDone() {
|
||||||
|
MutexLock l(&mutex_);
|
||||||
|
while (!done_with_sleep_) {
|
||||||
|
bg_cv_.Wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void DoSleepTask(void* arg) {
|
static void DoSleepTask(void* arg) {
|
||||||
reinterpret_cast<SleepingBackgroundTask*>(arg)->DoSleep();
|
reinterpret_cast<SleepingBackgroundTask*>(arg)->DoSleep();
|
||||||
|
@ -2276,6 +2285,7 @@ class SleepingBackgroundTask {
|
||||||
port::Mutex mutex_;
|
port::Mutex mutex_;
|
||||||
port::CondVar bg_cv_; // Signalled when background work finishes
|
port::CondVar bg_cv_; // Signalled when background work finishes
|
||||||
bool should_sleep_;
|
bool should_sleep_;
|
||||||
|
bool done_with_sleep_;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST(DBTest, GetProperty) {
|
TEST(DBTest, GetProperty) {
|
||||||
|
@ -2327,6 +2337,7 @@ TEST(DBTest, GetProperty) {
|
||||||
ASSERT_EQ(num, "0");
|
ASSERT_EQ(num, "0");
|
||||||
|
|
||||||
sleeping_task_high.WakeUp();
|
sleeping_task_high.WakeUp();
|
||||||
|
sleeping_task_high.WaitUntilDone();
|
||||||
dbfull()->TEST_WaitForFlushMemTable();
|
dbfull()->TEST_WaitForFlushMemTable();
|
||||||
|
|
||||||
ASSERT_OK(dbfull()->Put(writeOpt, "k4", big_value));
|
ASSERT_OK(dbfull()->Put(writeOpt, "k4", big_value));
|
||||||
|
@ -2337,6 +2348,7 @@ TEST(DBTest, GetProperty) {
|
||||||
ASSERT_TRUE(dbfull()->GetProperty("rocksdb.compaction-pending", &num));
|
ASSERT_TRUE(dbfull()->GetProperty("rocksdb.compaction-pending", &num));
|
||||||
ASSERT_EQ(num, "1");
|
ASSERT_EQ(num, "1");
|
||||||
sleeping_task_low.WakeUp();
|
sleeping_task_low.WakeUp();
|
||||||
|
sleeping_task_low.WaitUntilDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(DBTest, FLUSH) {
|
TEST(DBTest, FLUSH) {
|
||||||
|
|
Loading…
Reference in a new issue