Skip to content

Commit 3eb2484

Browse files
Aditya Shastrifacebook-github-bot
authored andcommitted
Address flaky test issue for LocalFileWriterTest (#123)
Summary: Pull Request resolved: #123 See T115000570. This test is flaky on `stress-runs` because it uses the same file name for every run. In this diff, we just add a random number Reviewed By: elliottlawrence Differential Revision: D35053135 fbshipit-source-id: 6dcb360007ecba0eed05921fdda8f431f2677601
1 parent cf5b501 commit 3eb2484

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

fbpcf/io/api/test/LocalFileWriterTest.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <gtest/gtest.h>
99
#include <stdio.h>
1010
#include <filesystem>
11+
#include <random>
1112
#include <string>
1213
#include "folly/logging/xlog.h"
1314

@@ -22,7 +23,12 @@ inline void cleanup(std::string fileToDelete) {
2223

2324
TEST(LocalFileWriterTest, testWritingToFile) {
2425
std::string baseDir = IOTestHelper::getBaseDirFromPath(__FILE__);
25-
std::string fileToWriteTo = baseDir + "data/local_file_writer_test_file.txt";
26+
std::random_device rd;
27+
std::default_random_engine defEngine(rd());
28+
std::uniform_int_distribution<int> intDistro(1, 25000);
29+
auto randint = intDistro(defEngine);
30+
std::string fileToWriteTo = baseDir + "data/local_file_writer_test_file" +
31+
std::to_string(randint) + ".txt";
2632
auto writer = std::make_unique<fbpcf::io::LocalFileWriter>(fileToWriteTo);
2733

2834
/*

fbpcf/io/api/test/utils/IOTestHelper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class IOTestHelper {
4545
auto test = testFile->get();
4646
EXPECT_EQ(test, expected);
4747
}
48+
49+
expectedFile->close();
50+
testFile->close();
4851
}
4952
};
5053

0 commit comments

Comments
 (0)