Skip to content

Commit e879746

Browse files
committed
test/objectstore/TestRocksdbOptionParse.cc: Fix race hazard
Race hazard - rocksdb does not register its threads until they start running, and only guarantees the threads have been created before returning. We need to be prepared to wait for the scheduler to run the threads to avoid false positives. Fixes: https://tracker.ceph.com/issues/66575 Signed-off-by: Bill Scales <[email protected]>
1 parent 9d95021 commit e879746

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)