Skip to content

Commit 58e9d14

Browse files
authored
Merge pull request ceph#58194 from bill-scales/fix_unittest_rocksdb_option
test/objectstore/TestRocksdbOptionParse.cc: Fix race hazard Reviewed-by: Igor Fedotov <[email protected]> Reviewed-by: Kefu Chai <[email protected]>
2 parents 1e37f66 + e879746 commit 58e9d14

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/test/objectstore/TestRocksdbOptionParse.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,20 @@ TEST(RocksDBOption, interpret) {
5555
ASSERT_EQ(0, r);
5656
ASSERT_TRUE(db->compact_on_mount);
5757
//check thread pool setting
58-
options.env->SleepForMicroseconds(100000);
5958
std::vector<rocksdb::ThreadStatus> thread_list;
60-
status = options.env->GetThreadList(&thread_list);
61-
ASSERT_TRUE(status.ok());
62-
59+
/* Race hazard - rocksdb does not register its threads until they start
60+
* running, and only guarantees the threads have been created before
61+
* returning. We need to be prepared to wait for the scheduler to
62+
* run the threads to avoid false positives.
63+
*/
64+
for (int attempt = 0; attempt < 50; attempt++) {
65+
options.env->SleepForMicroseconds(100000);
66+
status = options.env->GetThreadList(&thread_list);
67+
ASSERT_TRUE(status.ok());
68+
if (thread_list.size() >= 15u) {
69+
break;
70+
}
71+
}
6372
int num_high_pri_threads = 0;
6473
int num_low_pri_threads = 0;
6574
for (vector<rocksdb::ThreadStatus>::iterator it = thread_list.begin();

0 commit comments

Comments
 (0)