]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Make store_test_fixture create a random dir.
authorAlex Ainscow <aainscow@uk.ibm.com>
Fri, 27 Feb 2026 22:07:22 +0000 (22:07 +0000)
committerAlex Ainscow <aainscow@uk.ibm.com>
Tue, 24 Mar 2026 13:29:53 +0000 (13:29 +0000)
Signed-off-by: Alex Ainscow <aainscow@uk.ibm.com>
src/test/objectstore/store_test_fixture.cc
src/test/objectstore/store_test_fixture.h

index 62a199ceaeb9760bfb31002fc235ef213f40e033..fc43148621c02caa07985799caade216bbe0bb9c 100644 (file)
@@ -34,13 +34,16 @@ static void rm_r(const string& path)
 
 void StoreTestFixture::SetUp()
 {
-
-  int r = ::mkdir(data_dir.c_str(), 0777);
-  if (r < 0) {
-    r = -errno;
-    cerr << __func__ << ": unable to create " << data_dir << ": " << cpp_strerror(r) << std::endl;
+  // Create a unique temporary directory for this fixture instance so that
+  // tests can safely run in parallel without colliding on the same path.
+  std::string tmpl = type + ".test_temp_dir.XXXXXX";
+  char* tmp = ::mkdtemp(tmpl.data());
+  if (!tmp) {
+    int r = -errno;
+    cerr << __func__ << ": mkdtemp(" << tmpl << ") failed: " << cpp_strerror(r) << std::endl;
+    ASSERT_TRUE(tmp);
   }
-  ASSERT_EQ(0, r);
+  data_dir = tmp;
   store.reset(nullptr);
   store = ObjectStore::create(g_ceph_context,
                               type,
index afde3d3ec725b82ec62852ad1e412e48df607003..0f28b169ac6cb84ecb49259a33fc9667ead9666d 100644 (file)
@@ -13,14 +13,16 @@ class StoreTestFixture : virtual public ::testing::Test {
   ConfigProxy* conf = nullptr;
 
 protected:
-  const std::string data_dir;
+  // Unique per-instance temp directory, set in SetUp() via mkdtemp.
+  // Using a unique directory makes it safe to run tests in parallel.
+  std::string data_dir;
 
 public:
   std::unique_ptr<ObjectStore> store;
   ObjectStore::CollectionHandle ch;
 
   explicit StoreTestFixture(const std::string& type)
-    : type(type), data_dir(type + ".test_temp_dir")
+    : type(type)
   {}
 
   void SetUp() override;