[libcxx-commits] [PATCH] D98703: [libcxx] [test] Avoid race conditions between tests regarding temp directories

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 17 01:42:57 PDT 2021


mstorsjo updated this revision to Diff 331177.
mstorsjo retitled this revision from "[libcxx] [test] Readd randomness to temporary directory names" to "[libcxx] [test] Avoid race conditions between tests regarding temp directories".
mstorsjo edited the summary of this revision.
mstorsjo added a comment.

Squashed the two changes, using a hash of the full cwd instead of random chars.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98703/new/

https://reviews.llvm.org/D98703

Files:
  libcxx/test/support/filesystem_test_helper.h


Index: libcxx/test/support/filesystem_test_helper.h
===================================================================
--- libcxx/test/support/filesystem_test_helper.h
+++ libcxx/test/support/filesystem_test_helper.h
@@ -296,14 +296,17 @@
     // sharing the same cwd). However, it is fairly unlikely to happen as
     // we generally don't use scoped_test_env from multiple threads, so
     // this is deemed acceptable.
+    // The cwd.filename() itself isn't unique across all tests in the suite,
+    // so start the numbering from a hash of the full cwd, to avoid
+    // different tests interfering with each other.
     static inline fs::path available_cwd_path() {
         fs::path const cwd = utils::getcwd();
         fs::path const tmp = fs::temp_directory_path();
-        fs::path const base = tmp / cwd.filename();
-        int i = 0;
-        fs::path p = base / ("static_env." + std::to_string(i));
+        std::string base = cwd.filename().string();
+        size_t i = std::hash<std::string>()(cwd.string());
+        fs::path p = tmp / (base + "-static_env." + std::to_string(i));
         while (utils::exists(p.string())) {
-            p = fs::path(base) / ("static_env." + std::to_string(++i));
+            p = tmp / (base + "-static_env." + std::to_string(++i));
         }
         return p;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98703.331177.patch
Type: text/x-patch
Size: 1328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210317/455a2247/attachment.bin>


More information about the libcxx-commits mailing list