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,
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;