From 192c9be5308068662c6c45c2a3400b2f86227459 Mon Sep 17 00:00:00 2001 From: Aditya Shastri Date: Thu, 21 Apr 2022 14:54:26 -0700 Subject: [PATCH] Fix flaky tests for TLS (#824) Summary: Pull Request resolved: https://github.com/facebookresearch/fbpcs/pull/824 X-link: https://github.com/facebookresearch/fbpcf/pull/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 --- .../test/AggregationAppTest.cpp | 27 +++++++++++-------- .../test/AttributionAppTest.cpp | 24 ++++++++++------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/fbpcs/emp_games/pcf2_aggregation/test/AggregationAppTest.cpp b/fbpcs/emp_games/pcf2_aggregation/test/AggregationAppTest.cpp index 9e0e29e54..61e6369d3 100644 --- a/fbpcs/emp_games/pcf2_aggregation/test/AggregationAppTest.cpp +++ b/fbpcs/emp_games/pcf2_aggregation/test/AggregationAppTest.cpp @@ -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:: @@ -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( inputEncryption, @@ -78,7 +79,8 @@ inline void testCorrectnessAggregationAppHelper( std::vector inputClearTextPathBob, std::vector outputPathBob, std::vector expectedOutputFilePaths, - bool useTls) { + bool useTls, + std::string& tlsDir) { auto futureAlice = std::async( runGame, serverIpAlice, @@ -87,7 +89,8 @@ inline void testCorrectnessAggregationAppHelper( inputSecretSharePathAlice.at(id), inputClearTextPathAlice.at(id), outputPathAlice.at(id), - useTls); + useTls, + tlsDir); auto futureBob = std::async( runGame, serverIpBob, @@ -96,7 +99,8 @@ inline void testCorrectnessAggregationAppHelper( inputSecretSharePathBob.at(id), inputClearTextPathBob.at(id), outputPathBob.at(id), - useTls); + useTls, + tlsDir); futureAlice.get(); futureBob.get(); @@ -135,7 +139,8 @@ inline void testCorrectnessAggregationAppHelper( inputClearTextPathBob, outputPathBob, expectedOutputFilePaths, - useTls); + useTls, + tlsDir); } } } @@ -144,8 +149,7 @@ class AggregationAppTest : public ::testing::TestWithParam< std::tuple> { 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__); @@ -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 @@ -214,7 +217,8 @@ class AggregationAppTest : public ::testing::TestWithParam< inputClearTextFilePathsBob_, outputFilePathsBob_, expectedOutputFilePaths_, - useTls); + useTls, + tlsDir_); } std::string serverIpAlice_; @@ -231,6 +235,7 @@ class AggregationAppTest : public ::testing::TestWithParam< std::vector outputFilePathsAlice_; std::vector outputFilePathsBob_; std::vector expectedOutputFilePaths_; + std::string tlsDir_; }; TEST_P(AggregationAppTest, TestCorrectness) { diff --git a/fbpcs/emp_games/pcf2_attribution/test/AttributionAppTest.cpp b/fbpcs/emp_games/pcf2_attribution/test/AttributionAppTest.cpp index 4dd2984f2..01dd2fac3 100644 --- a/fbpcs/emp_games/pcf2_attribution/test/AttributionAppTest.cpp +++ b/fbpcs/emp_games/pcf2_attribution/test/AttributionAppTest.cpp @@ -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:: @@ -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( std::move(communicationAgentFactory), @@ -65,7 +66,8 @@ inline void testCorrectnessAttributionAppHelper( std::vector inputPathBob, std::vector outputPathBob, std::vector expectedOutputFilenames, - bool useTls) { + bool useTls, + std::string& tlsDir) { auto futureAlice = std::async( runGame, serverIpAlice, @@ -73,7 +75,8 @@ inline void testCorrectnessAttributionAppHelper( attributionRule.at(id), inputPathAlice.at(id), outputPathAlice.at(id), - useTls); + useTls, + tlsDir); auto futureBob = std::async( runGame, serverIpBob, @@ -81,7 +84,8 @@ inline void testCorrectnessAttributionAppHelper( "", inputPathBob.at(id), outputPathBob.at(id), - useTls); + useTls, + tlsDir); futureAlice.wait(); futureBob.wait(); @@ -101,8 +105,7 @@ class AttributionAppTest std::tuple> { // 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__); @@ -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 @@ -154,7 +156,8 @@ class AttributionAppTest inputFilenamesBob_, outputFilenamesBob_, expectedOutputFilenames_, - useTls); + useTls, + tlsDir_); } std::string serverIpAlice_; @@ -168,6 +171,7 @@ class AttributionAppTest std::vector outputFilenamesAlice_; std::vector outputFilenamesBob_; std::vector expectedOutputFilenames_; + std::string tlsDir_; }; TEST_P(AttributionAppTest, TestCorrectness) {