Skip to content

Commit

Permalink
Fix other occasional TSan failures in S3 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Jul 7, 2023
1 parent 69bf7b3 commit 084180f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
11 changes: 11 additions & 0 deletions cpp/src/arrow/filesystem/s3_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "arrow/filesystem/s3fs.h"
#include "arrow/status.h"
#include "arrow/testing/gtest_util.h"
#include "arrow/testing/util.h"
#include "arrow/util/checked_cast.h"
#include "arrow/util/macros.h"

Expand Down Expand Up @@ -76,6 +77,13 @@ class MinioTestEnvironment : public ::testing::Environment {

class S3Environment : public ::testing::Environment {
public:
// We set this environment variable to speed up tests by ensuring
// DefaultAWSCredentialsProviderChain does not query (inaccessible)
// EC2 metadata endpoint.
// This must be done before spawning any Minio child process to avoid any race
// condition accessing environment variables.
S3Environment() : ec2_metadata_disabled_guard_("AWS_EC2_METADATA_DISABLED", "true") {}

void SetUp() override {
// Change this to increase logging during tests
S3GlobalOptions options;
Expand All @@ -84,6 +92,9 @@ class S3Environment : public ::testing::Environment {
}

void TearDown() override { ASSERT_OK(FinalizeS3()); }

private:
EnvVarGuard ec2_metadata_disabled_guard_;
};

} // namespace fs
Expand Down
7 changes: 0 additions & 7 deletions cpp/src/arrow/filesystem/s3fs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#include "arrow/testing/future_util.h"
#include "arrow/testing/gtest_util.h"
#include "arrow/testing/matchers.h"
#include "arrow/testing/util.h"
#include "arrow/util/async_generator.h"
#include "arrow/util/checked_cast.h"
#include "arrow/util/future.h"
Expand Down Expand Up @@ -146,11 +145,6 @@ class ShortRetryStrategy : public S3RetryStrategy {

class AwsTestMixin : public ::testing::Test {
public:
// We set this environment variable to speed up tests by ensuring
// DefaultAWSCredentialsProviderChain does not query (inaccessible)
// EC2 metadata endpoint
AwsTestMixin() : ec2_metadata_disabled_guard_("AWS_EC2_METADATA_DISABLED", "true") {}

void SetUp() override {
#ifdef AWS_CPP_SDK_S3_NOT_SHARED
auto aws_log_level = Aws::Utils::Logging::LogLevel::Fatal;
Expand All @@ -169,7 +163,6 @@ class AwsTestMixin : public ::testing::Test {
}

private:
EnvVarGuard ec2_metadata_disabled_guard_;
#ifdef AWS_CPP_SDK_S3_NOT_SHARED
Aws::SDKOptions aws_options_;
#endif
Expand Down
4 changes: 3 additions & 1 deletion cpp/src/arrow/util/io_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <random>
#include <sstream>
#include <string>
#include <string_view>
#include <thread>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -1896,7 +1897,8 @@ std::vector<NativePathString> GetPlatformTemporaryDirs() {
}

std::string MakeRandomName(int num_chars) {
static const std::string chars = "0123456789abcdefghijklmnopqrstuvwxyz";
constexpr std::string_view chars = "0123456789abcdefghijklmnopqrstuvwxyz";

std::default_random_engine gen(
static_cast<std::default_random_engine::result_type>(GetRandomSeed()));
std::uniform_int_distribution<int> dist(0, static_cast<int>(chars.length() - 1));
Expand Down

0 comments on commit 084180f

Please sign in to comment.