]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/objectstore/TestRocksdbOptionParse.cc: Fix race hazard 58194/head
authorBill Scales <bill_scales@uk.ibm.com>
Thu, 20 Jun 2024 09:46:17 +0000 (09:46 +0000)
committerBill Scales <bill_scales@uk.ibm.com>
Fri, 21 Jun 2024 10:39:38 +0000 (10:39 +0000)
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 <bill_scales@uk.ibm.com>
src/test/objectstore/TestRocksdbOptionParse.cc

index 986eea8f16ce360857208402570b6fd07f297196..763b951cb8a7a2cb4e19746c502947669aeeaacf 100644 (file)
@@ -55,11 +55,20 @@ TEST(RocksDBOption, interpret) {
   ASSERT_EQ(0, r);
   ASSERT_TRUE(db->compact_on_mount);
   //check thread pool setting
-  options.env->SleepForMicroseconds(100000);
   std::vector<rocksdb::ThreadStatus> thread_list;
-  status = options.env->GetThreadList(&thread_list);
-  ASSERT_TRUE(status.ok());
-
+  /* 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.
+   */
+  for (int attempt = 0; attempt < 50; attempt++) {
+    options.env->SleepForMicroseconds(100000);
+    status = options.env->GetThreadList(&thread_list);
+    ASSERT_TRUE(status.ok());
+    if (thread_list.size() >= 15u) {
+      break;
+    }
+  }
   int num_high_pri_threads = 0;
   int num_low_pri_threads = 0;
   for (vector<rocksdb::ThreadStatus>::iterator it = thread_list.begin();