[PATCH] D56336: [Support] unflake TempFileCollisions test

Bob Haarman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 4 14:37:51 PST 2019


inglorion created this revision.
inglorion added a reviewer: fedor.sergeev.

This test was added to verify that createUniqueEntity() does
not enter an infinite loop when all possible names are taken. However,
it also checked that all possible names are generated, which is flaky
(because the names are generated randomly). This changes removes the
constraint on number of names successfully generated to stop the test
from being flaky.


https://reviews.llvm.org/D56336

Files:
  llvm/unittests/Support/Path.cpp


Index: llvm/unittests/Support/Path.cpp
===================================================================
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -701,10 +701,14 @@
     }
   };
 
-  // We should be able to create exactly 16 temporary files.
-  for (int i = 0; i < 16; ++i)
-    EXPECT_TRUE(TryCreateTempFile());
-  EXPECT_FALSE(TryCreateTempFile());
+  // Our single-character template allows for 16 unique names. Check that
+  // attempting to generate 17 results in TryCreateTempFile returning false
+  // (rather than something less desirable, such as infinite looping).
+  // This may happen before the 17th attempt due to the way names are generated.
+  bool Succeeded = true;
+  for (int i = 0; i < 17; ++i)
+    if (TryCreateTempFile()) Succeeded = false;
+  EXPECT_FALSE(Succeeded);
 
   for (fs::TempFile &T : TempFiles)
     cantFail(T.discard());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56336.180328.patch
Type: text/x-patch
Size: 895 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190104/e9bdaac3/attachment.bin>


More information about the llvm-commits mailing list