From 1b295ac8ae6a4871e8bf1b181558f7f49a9ee3bc Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Sat, 29 Oct 2016 15:58:45 -0700 Subject: [PATCH] DBTest.GetThreadStatus: Wait for test results for longer Summary: The current 10 millisecond waiting for test results may not be sufficient in some test environments. Increase it to 60 seconds and check the results for every 1 milliseond. Already reviewed: https://reviews.facebook.net/D65457 Closes https://github.com/facebook/rocksdb/pull/1437 Differential Revision: D4099443 Pulled By: siying fbshipit-source-id: cf1f205 --- db/db_test.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/db/db_test.cc b/db/db_test.cc index 2ca489384..d3a82881a 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -3646,14 +3646,24 @@ TEST_F(DBTest, GetThreadStatus) { env_->SetBackgroundThreads(kHighPriCounts[test], Env::HIGH); env_->SetBackgroundThreads(kLowPriCounts[test], Env::LOW); // Wait to ensure the all threads has been registered - env_->SleepForMicroseconds(100000); - s = env_->GetThreadList(&thread_list); - ASSERT_OK(s); unsigned int thread_type_counts[ThreadStatus::NUM_THREAD_TYPES]; - memset(thread_type_counts, 0, sizeof(thread_type_counts)); - for (auto thread : thread_list) { - ASSERT_LT(thread.thread_type, ThreadStatus::NUM_THREAD_TYPES); - thread_type_counts[thread.thread_type]++; + // Try up to 60 seconds. + for (int num_try = 0; num_try < 60000; num_try++) { + env_->SleepForMicroseconds(1000); + thread_list.clear(); + s = env_->GetThreadList(&thread_list); + ASSERT_OK(s); + memset(thread_type_counts, 0, sizeof(thread_type_counts)); + for (auto thread : thread_list) { + ASSERT_LT(thread.thread_type, ThreadStatus::NUM_THREAD_TYPES); + thread_type_counts[thread.thread_type]++; + } + if (thread_type_counts[ThreadStatus::HIGH_PRIORITY] == + kHighPriCounts[test] && + thread_type_counts[ThreadStatus::LOW_PRIORITY] == + kLowPriCounts[test]) { + break; + } } // Verify the total number of threades ASSERT_EQ(thread_type_counts[ThreadStatus::HIGH_PRIORITY] +