Skip to content

Commit 2eea99a

Browse files
committed
[Support] unflake TempFileCollisions test
Summary: 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 change increases the number of attempts we make to make flakes exceedingly unlikely (3.88e-62). Reviewers: fedor.sergeev, rsmith Reviewed By: fedor.sergeev Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D56336 llvm-svn: 358914
1 parent d8d9b7b commit 2eea99a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

llvm/unittests/Support/Path.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,18 @@ TEST_F(FileSystemTest, TempFileCollisions) {
700700
}
701701
};
702702

703-
// We should be able to create exactly 16 temporary files.
704-
for (int i = 0; i < 16; ++i)
705-
EXPECT_TRUE(TryCreateTempFile());
706-
EXPECT_FALSE(TryCreateTempFile());
703+
// Our single-character template allows for 16 unique names. Check that
704+
// calling TryCreateTempFile repeatedly results in 16 successes.
705+
// Because the test depends on random numbers, it could theoretically fail.
706+
// However, the probability of this happening is tiny: with 32 calls, each
707+
// of which will retry up to 128 times, to not get a given digit we would
708+
// have to fail at least 15 + 17 * 128 = 2191 attempts. The probability of
709+
// 2191 attempts not producing a given hexadecimal digit is
710+
// (1 - 1/16) ** 2191 or 3.88e-62.
711+
int Successes = 0;
712+
for (int i = 0; i < 32; ++i)
713+
if (TryCreateTempFile()) ++Successes;
714+
EXPECT_EQ(Successes, 16);
707715

708716
for (fs::TempFile &T : TempFiles)
709717
cantFail(T.discard());

0 commit comments

Comments
 (0)