Skip to content

Commit

Permalink
Fix flaky tests for TLS (#824)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #824

X-link: facebookresearch/fbpcf#194

I think this is happening on stress runs because the helper function to generate certs just stores it in the same place (/tmp), so two parallel test runs could interfere with each other

Reviewed By: chualynn

Differential Revision: D35824204

fbshipit-source-id: b03bc0314076fdf6866a648e24f18712613dc15a
  • Loading branch information
adshastri authored and facebook-github-bot committed Apr 21, 2022
1 parent 9515339 commit 192c9be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
27 changes: 16 additions & 11 deletions fbpcs/emp_games/pcf2_aggregation/test/AggregationAppTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ static void runGame(
const std::filesystem::path& inputSecretSharePath,
const std::filesystem::path& inputClearTextPath,
const std::string& outputPath,
bool useTls) {
bool useTls,
const std::string& tlsDir) {
std::map<
int,
fbpcf::engine::communication::SocketPartyCommunicationAgentFactory::
Expand All @@ -45,7 +46,7 @@ static void runGame(

auto communicationAgentFactory = std::make_unique<
fbpcf::engine::communication::SocketPartyCommunicationAgentFactory>(
PARTY, partyInfos, useTls, std::filesystem::temp_directory_path());
PARTY, partyInfos, useTls, tlsDir);

AggregationApp<PARTY, schedulerId>(
inputEncryption,
Expand Down Expand Up @@ -78,7 +79,8 @@ inline void testCorrectnessAggregationAppHelper(
std::vector<std::string> inputClearTextPathBob,
std::vector<std::string> outputPathBob,
std::vector<std::string> expectedOutputFilePaths,
bool useTls) {
bool useTls,
std::string& tlsDir) {
auto futureAlice = std::async(
runGame<common::PUBLISHER, 2 * id, outputVisibility, inputEncryption>,
serverIpAlice,
Expand All @@ -87,7 +89,8 @@ inline void testCorrectnessAggregationAppHelper(
inputSecretSharePathAlice.at(id),
inputClearTextPathAlice.at(id),
outputPathAlice.at(id),
useTls);
useTls,
tlsDir);
auto futureBob = std::async(
runGame<common::PARTNER, 2 * id + 1, outputVisibility, inputEncryption>,
serverIpBob,
Expand All @@ -96,7 +99,8 @@ inline void testCorrectnessAggregationAppHelper(
inputSecretSharePathBob.at(id),
inputClearTextPathBob.at(id),
outputPathBob.at(id),
useTls);
useTls,
tlsDir);

futureAlice.get();
futureBob.get();
Expand Down Expand Up @@ -135,7 +139,8 @@ inline void testCorrectnessAggregationAppHelper(
inputClearTextPathBob,
outputPathBob,
expectedOutputFilePaths,
useTls);
useTls,
tlsDir);
}
}
}
Expand All @@ -144,8 +149,7 @@ class AggregationAppTest : public ::testing::TestWithParam<
std::tuple<int, common::Visibility, bool>> {
protected:
void SetUp() override {
fbpcf::engine::communication::setUpTlsFiles(
std::filesystem::temp_directory_path());
tlsDir_ = fbpcf::engine::communication::setUpTlsFiles();
port_ = 5000 + folly::Random::rand32() % 1000;
std::string baseDir_ =
private_measurement::test_util::getBaseDirFromPath(__FILE__);
Expand Down Expand Up @@ -190,8 +194,7 @@ class AggregationAppTest : public ::testing::TestWithParam<
void TearDown() override {
std::filesystem::remove(outputPathAlice_);
std::filesystem::remove(outputPathBob_);
fbpcf::engine::communication::deleteTlsFiles(
std::filesystem::temp_directory_path());
fbpcf::engine::communication::deleteTlsFiles(tlsDir_);
}

template <int id, common::Visibility visibility>
Expand All @@ -214,7 +217,8 @@ class AggregationAppTest : public ::testing::TestWithParam<
inputClearTextFilePathsBob_,
outputFilePathsBob_,
expectedOutputFilePaths_,
useTls);
useTls,
tlsDir_);
}

std::string serverIpAlice_;
Expand All @@ -231,6 +235,7 @@ class AggregationAppTest : public ::testing::TestWithParam<
std::vector<std::string> outputFilePathsAlice_;
std::vector<std::string> outputFilePathsBob_;
std::vector<std::string> expectedOutputFilePaths_;
std::string tlsDir_;
};

TEST_P(AggregationAppTest, TestCorrectness) {
Expand Down
24 changes: 14 additions & 10 deletions fbpcs/emp_games/pcf2_attribution/test/AttributionAppTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ static void runGame(
const std::string& attributionRules,
const std::filesystem::path& inputPath,
const std::string& outputPath,
bool useTls) {
bool useTls,
const std::string& tlsDir) {
std::map<
int,
fbpcf::engine::communication::SocketPartyCommunicationAgentFactory::
Expand All @@ -42,7 +43,7 @@ static void runGame(

auto communicationAgentFactory = std::make_unique<
fbpcf::engine::communication::SocketPartyCommunicationAgentFactory>(
PARTY, partyInfos, useTls, std::filesystem::temp_directory_path());
PARTY, partyInfos, useTls, tlsDir);

AttributionApp<PARTY, schedulerId, usingBatch, inputEncryption>(
std::move(communicationAgentFactory),
Expand All @@ -65,23 +66,26 @@ inline void testCorrectnessAttributionAppHelper(
std::vector<std::string> inputPathBob,
std::vector<std::string> outputPathBob,
std::vector<std::string> expectedOutputFilenames,
bool useTls) {
bool useTls,
std::string& tlsDir) {
auto futureAlice = std::async(
runGame<common::PUBLISHER, 2 * id, usingBatch, inputEncryption>,
serverIpAlice,
portAlice + 100 * id,
attributionRule.at(id),
inputPathAlice.at(id),
outputPathAlice.at(id),
useTls);
useTls,
tlsDir);
auto futureBob = std::async(
runGame<common::PARTNER, 2 * id + 1, usingBatch, inputEncryption>,
serverIpBob,
portBob + 100 * id,
"",
inputPathBob.at(id),
outputPathBob.at(id),
useTls);
useTls,
tlsDir);

futureAlice.wait();
futureBob.wait();
Expand All @@ -101,8 +105,7 @@ class AttributionAppTest
std::tuple<int, bool, bool>> { // id, usingBatch, useTls
protected:
void SetUp() override {
fbpcf::engine::communication::setUpTlsFiles(
std::filesystem::temp_directory_path());
tlsDir_ = fbpcf::engine::communication::setUpTlsFiles();
port_ = 5000 + folly::Random::rand32() % 1000;
std::string baseDir_ =
private_measurement::test_util::getBaseDirFromPath(__FILE__);
Expand Down Expand Up @@ -134,8 +137,7 @@ class AttributionAppTest
void TearDown() override {
std::filesystem::remove(outputPathAlice_);
std::filesystem::remove(outputPathBob_);
fbpcf::engine::communication::deleteTlsFiles(
std::filesystem::temp_directory_path());
fbpcf::engine::communication::deleteTlsFiles(tlsDir_);
}

template <int id, bool usingBatch>
Expand All @@ -154,7 +156,8 @@ class AttributionAppTest
inputFilenamesBob_,
outputFilenamesBob_,
expectedOutputFilenames_,
useTls);
useTls,
tlsDir_);
}

std::string serverIpAlice_;
Expand All @@ -168,6 +171,7 @@ class AttributionAppTest
std::vector<std::string> outputFilenamesAlice_;
std::vector<std::string> outputFilenamesBob_;
std::vector<std::string> expectedOutputFilenames_;
std::string tlsDir_;
};

TEST_P(AttributionAppTest, TestCorrectness) {
Expand Down

0 comments on commit 192c9be

Please sign in to comment.