From e5a54ef71df81121c72599bc9a9fb806798d2885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20P=C3=A9r=C3=A9?= Date: Tue, 11 Jun 2024 10:44:57 +0200 Subject: [PATCH] fix(compiler): fix racing the test directories on mac --- .../concretelang/TestLib/TestProgram.h | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/compilers/concrete-compiler/compiler/include/concretelang/TestLib/TestProgram.h b/compilers/concrete-compiler/compiler/include/concretelang/TestLib/TestProgram.h index 070a137599..5e3be16373 100644 --- a/compilers/concrete-compiler/compiler/include/concretelang/TestLib/TestProgram.h +++ b/compilers/concrete-compiler/compiler/include/concretelang/TestLib/TestProgram.h @@ -23,6 +23,7 @@ #include #include #include +#include using concretelang::clientlib::ClientCircuit; using concretelang::clientlib::ClientProgram; @@ -220,37 +221,32 @@ class TestProgram { auto new_path = [=]() { llvm::SmallString<0> outputPath; llvm::sys::path::append(outputPath, rootFolder); - std::string uid = std::to_string( - std::hash()(std::this_thread::get_id())); + auto pid = getpid(); + std::string uid = std::to_string(pid); uid.append("-"); uid.append(std::to_string(std::rand())); llvm::sys::path::append(outputPath, uid); return std::string(outputPath); }; - // Macos sometimes fail to create new directories. We have to retry a few - // times. - for (size_t i = 0; i < 5; i++) { - auto pathString = new_path(); - auto ec = std::error_code(); - llvm::errs() << "TestProgram: create temporary directory(" << pathString - << ")\n"; - if (!std::filesystem::create_directory(pathString, ec)) { - llvm::errs() << "TestProgram: fail to create temporary directory(" - << pathString << "), "; - if (ec) { - llvm::errs() << "already exists"; - } else { - llvm::errs() << "error(" << ec.message() << ")"; - } + auto pathString = new_path(); + auto ec = std::error_code(); + llvm::errs() << "TestProgram: create temporary directory(" << pathString + << ")\n"; + if (!std::filesystem::create_directory(pathString, ec)) { + llvm::errs() << "TestProgram: fail to create temporary directory(" + << pathString << "), "; + if (ec) { + llvm::errs() << "already exists"; } else { - llvm::errs() << "TestProgram: directory(" << pathString - << ") successfully created\n"; - return pathString; + llvm::errs() << "error(" << ec.message() << ")"; } + assert(false); + } else { + llvm::errs() << "TestProgram: directory(" << pathString + << ") successfully created\n"; + return pathString; } - llvm::errs() << "Failed to create temp directory 5 times. Aborting...\n"; - assert(false); } };