Make file/directory related tests safe for concurrent execution
Providing unique identifiers for files and directories created as part
of unit tests.
Bug: webrtc:15833
Change-Id: If2835c362c47a111aa99b0e3c6ad6a33be061978
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/338260
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41704}
diff --git a/common_audio/BUILD.gn b/common_audio/BUILD.gn
index 2ae6d32..620d01e 100644
--- a/common_audio/BUILD.gn
+++ b/common_audio/BUILD.gn
@@ -375,6 +375,7 @@
"../rtc_base:checks",
"../rtc_base:macromagic",
"../rtc_base:rtc_base_tests_utils",
+ "../rtc_base:ssl",
"../rtc_base:stringutils",
"../rtc_base:timeutils",
"../rtc_base/system:arch",
diff --git a/common_audio/wav_file_unittest.cc b/common_audio/wav_file_unittest.cc
index 97cecc3..6a0cfdc 100644
--- a/common_audio/wav_file_unittest.cc
+++ b/common_audio/wav_file_unittest.cc
@@ -17,6 +17,7 @@
#include <limits>
#include "common_audio/wav_header.h"
+#include "rtc_base/helpers.h"
#include "test/gtest.h"
#include "test/testsupport/file_utils.h"
@@ -35,7 +36,8 @@
// Write a tiny WAV file with the C++ interface and verify the result.
TEST(WavWriterTest, MAYBE_CPP) {
- const std::string outfile = test::OutputPath() + "wavtest1.wav";
+ const std::string outfile =
+ test::OutputPath() + "wavtest1-" + rtc::CreateRandomUuid() + ".wav";
static const size_t kNumSamples = 3;
{
WavWriter w(outfile, 14099, 1);
diff --git a/modules/audio_device/BUILD.gn b/modules/audio_device/BUILD.gn
index 2088e74..baba0a3 100644
--- a/modules/audio_device/BUILD.gn
+++ b/modules/audio_device/BUILD.gn
@@ -488,6 +488,7 @@
"../../rtc_base:race_checker",
"../../rtc_base:rtc_event",
"../../rtc_base:safe_conversions",
+ "../../rtc_base:ssl",
"../../rtc_base:timeutils",
"../../rtc_base/synchronization:mutex",
"../../system_wrappers",
diff --git a/modules/audio_device/include/test_audio_device_unittest.cc b/modules/audio_device/include/test_audio_device_unittest.cc
index 7a122ca..d79697b 100644
--- a/modules/audio_device/include/test_audio_device_unittest.cc
+++ b/modules/audio_device/include/test_audio_device_unittest.cc
@@ -24,6 +24,7 @@
#include "common_audio/wav_header.h"
#include "modules/audio_device/include/audio_device_defines.h"
#include "rtc_base/checks.h"
+#include "rtc_base/helpers.h"
#include "rtc_base/logging.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/gmock.h"
@@ -41,7 +42,7 @@
const std::string output_filename =
test::OutputPath() + "BoundedWavFileWriterTest_" + test_info->name() +
- "_" + std::to_string(std::rand()) + ".wav";
+ "_" + rtc::CreateRandomUuid() + ".wav";
static const size_t kSamplesPerFrame = 8;
static const int kSampleRate = kSamplesPerFrame * 100;
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 185f12c..574496f 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -950,6 +950,7 @@
":fileutils",
":test_support",
"../rtc_base:checks",
+ "../rtc_base:ssl",
]
absl_deps = [
"//third_party/abseil-cpp/absl/strings:strings",
diff --git a/test/testsupport/file_utils_unittest.cc b/test/testsupport/file_utils_unittest.cc
index b9de01d..666d574 100644
--- a/test/testsupport/file_utils_unittest.cc
+++ b/test/testsupport/file_utils_unittest.cc
@@ -19,6 +19,7 @@
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "rtc_base/checks.h"
+#include "rtc_base/helpers.h"
#include "test/gmock.h"
#include "test/gtest.h"
@@ -147,7 +148,8 @@
#define MAYBE_CreateDir CreateDir
#endif
TEST_F(FileUtilsTest, MAYBE_CreateDir) {
- std::string directory = "fileutils-unittest-empty-dir";
+ std::string directory = test::OutputPath() + "fileutils-unittest-empty-dir" +
+ rtc::CreateRandomUuid();
// Make sure it's removed if a previous test has failed:
remove(directory.c_str());
ASSERT_TRUE(webrtc::test::CreateDir(directory));
@@ -231,7 +233,8 @@
// Create an empty temporary directory for this test.
const std::string temp_directory =
- OutputPath() + Path("TempFileUtilsTestReadDirectory/");
+ OutputPath() +
+ Path("TempFileUtilsTestReadDirectory" + rtc::CreateRandomUuid() + "/");
CreateDir(temp_directory);
EXPECT_NO_FATAL_FAILURE(CleanDir(temp_directory, &num_deleted_entries));
EXPECT_TRUE(DirExists(temp_directory));