Skip to content

Commit

Permalink
Perform InitAPI ShutdownAPI per each test suite in S3 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyRyabinin committed Apr 15, 2024
1 parent 1ddf39e commit 632885a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0.
*/

#include <gtest/gtest.h>
#include <aws/testing/AwsCppSdkGTestSuite.h>
#include <aws/testing/AwsTestHelpers.h>
#include <aws/core/auth/AWSCredentialsProviderChain.h>
#include <aws/core/client/ClientConfiguration.h>
Expand Down Expand Up @@ -150,22 +150,23 @@ namespace
long CalculateDelayBeforeNextRetry(const AWSError<CoreErrors>&, long) const override { return 0; }
};

class BucketAndObjectOperationTest : public ::testing::Test
class BucketAndObjectOperationTest : public Aws::Testing::AwsCppSdkGTestSuite
{
public:
static std::shared_ptr<S3Client> Client;
static std::shared_ptr<S3Client> globalClient;
static std::shared_ptr<S3Client> oregonClient;
static std::shared_ptr<S3Client> retryClient;
static std::shared_ptr<HttpClientFactory> ClientFactory;
static std::shared_ptr<HttpClient> m_HttpClient;
static std::shared_ptr<Aws::Utils::RateLimits::RateLimiterInterface> Limiter;
std::shared_ptr<S3Client> Client;
std::shared_ptr<S3Client> globalClient;
std::shared_ptr<S3Client> oregonClient;
std::shared_ptr<S3Client> retryClient;
std::shared_ptr<HttpClientFactory> ClientFactory;
std::shared_ptr<HttpClient> m_HttpClient;
std::shared_ptr<Aws::Utils::RateLimits::RateLimiterInterface> Limiter;

protected:

static void SetUpTestCase()
void SetUp() override
{
EnsureUniqueBucketNames();
static std::once_flag flag;
std::call_once(flag, EnsureUniqueBucketNames);

Limiter = Aws::MakeShared<Aws::Utils::RateLimits::DefaultRateLimiter<>>(ALLOCATION_TAG, 50000000);

Expand Down Expand Up @@ -209,7 +210,7 @@ namespace
TestingMonitoringManager::InitTestingMonitoring();
}

static void TearDownTestCase()
void TearDown() override
{
TestingMonitoringManager::CleanupTestingMonitoring();
DeleteBucket(CalculateBucketName(BASE_CREATE_BUCKET_TEST_NAME.c_str()));
Expand Down Expand Up @@ -262,9 +263,9 @@ namespace
return streamPtr;
}

static UploadPartOutcomeCallable MakeUploadPartOutcomeAndGetCallable(unsigned partNumber, const ByteBuffer& md5OfStream,
const std::shared_ptr<Aws::IOStream>& partStream,
const Aws::String& bucketName, const char* objectName, const Aws::String& uploadId)
UploadPartOutcomeCallable MakeUploadPartOutcomeAndGetCallable(unsigned partNumber, const ByteBuffer& md5OfStream,
const std::shared_ptr<Aws::IOStream>& partStream,
const Aws::String& bucketName, const char* objectName, const Aws::String& uploadId)
{
UploadPartRequest uploadPart1Request;
uploadPart1Request.SetBucket(bucketName);
Expand Down Expand Up @@ -307,8 +308,13 @@ namespace
AWS_ASSERT_SUCCESS(taggingOutcome);
}

static bool WaitForBucketToPropagate(const Aws::String& bucketName, const std::shared_ptr<S3Client>& client = Client)
bool WaitForBucketToPropagate(const Aws::String& bucketName, std::shared_ptr<S3Client>& client)
{
if (!client)
{
client = Client;
}

unsigned timeoutCount = 0;
while (timeoutCount++ < TIMEOUT_MAX)
{
Expand All @@ -326,7 +332,7 @@ namespace
return false;
}

static bool WaitForObjectToPropagate(const Aws::String& bucketName, const char* objectKey)
bool WaitForObjectToPropagate(const Aws::String& bucketName, const char* objectKey)
{
unsigned timeoutCount = 0;
while (timeoutCount++ < TIMEOUT_MAX)
Expand All @@ -346,7 +352,7 @@ namespace
return false;
}

static bool WaitForObjectWithSSECToPropagate(const Aws::String& bucketName, const char* objectKey, const ByteBuffer& sseKey)
bool WaitForObjectWithSSECToPropagate(const Aws::String& bucketName, const char* objectKey, const ByteBuffer& sseKey)
{
unsigned timeoutCount = 0;
Aws::String strBuffer(reinterpret_cast<char*>(sseKey.GetUnderlyingData()), sseKey.GetLength());
Expand All @@ -370,7 +376,7 @@ namespace
return false;
}

static void EmptyBucket(const Aws::String& bucketName)
void EmptyBucket(const Aws::String& bucketName)
{
ListObjectsRequest listObjectsRequest;
listObjectsRequest.SetBucket(bucketName);
Expand All @@ -390,7 +396,7 @@ namespace
}
}

static void WaitForBucketToEmpty(const Aws::String& bucketName)
void WaitForBucketToEmpty(const Aws::String& bucketName)
{
ListObjectsRequest listObjectsRequest;
listObjectsRequest.SetBucket(bucketName);
Expand All @@ -412,7 +418,7 @@ namespace
}
}

static void DeleteBucket(const Aws::String& bucketName)
void DeleteBucket(const Aws::String& bucketName)
{
HeadBucketRequest headBucketRequest;
headBucketRequest.SetBucket(bucketName);
Expand All @@ -436,7 +442,7 @@ namespace
return Aws::Testing::GetAwsResourcePrefix() + bucketPrefix;
}

static Aws::String PreparePresignedUrlTest()
Aws::String PreparePresignedUrlTest()
{
Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_PRESIGNED_URLS_BUCKET_NAME.c_str());
CreateBucketRequest createBucketRequest;
Expand All @@ -446,12 +452,12 @@ namespace
AWS_EXPECT_SUCCESS(createBucketOutcome);
const CreateBucketResult& createBucketResult = createBucketOutcome.GetResult();
EXPECT_TRUE(!createBucketResult.GetLocation().empty());
EXPECT_TRUE(WaitForBucketToPropagate(fullBucketName));
EXPECT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);
return fullBucketName;
}

static void DoPresignedUrlTest(const Aws::String& bucketName, std::shared_ptr<HttpRequest>& putRequest)
void DoPresignedUrlTest(const Aws::String& bucketName, std::shared_ptr<HttpRequest>& putRequest)
{
std::shared_ptr<Aws::IOStream> objectStream = Aws::MakeShared<Aws::StringStream>("BucketAndObjectOperationTest");
*objectStream << "Test Object";
Expand Down Expand Up @@ -488,7 +494,7 @@ namespace
}
}

static void CleanUpPresignedUrlTest()
void CleanUpPresignedUrlTest()
{
Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_PRESIGNED_URLS_BUCKET_NAME.c_str());
Aws::String presignedUrlDelete = Client->GeneratePresignedUrl(fullBucketName, TEST_OBJ_KEY, HttpMethod::HTTP_DELETE);
Expand Down Expand Up @@ -659,15 +665,6 @@ namespace

};


std::shared_ptr<S3Client> BucketAndObjectOperationTest::Client(nullptr);
std::shared_ptr<S3Client> BucketAndObjectOperationTest::globalClient(nullptr);
std::shared_ptr<S3Client> BucketAndObjectOperationTest::oregonClient(nullptr);
std::shared_ptr<S3Client> BucketAndObjectOperationTest::retryClient(nullptr);
std::shared_ptr<HttpClientFactory> BucketAndObjectOperationTest::ClientFactory(nullptr);
std::shared_ptr<HttpClient> BucketAndObjectOperationTest::m_HttpClient(nullptr);
std::shared_ptr<Aws::Utils::RateLimits::RateLimiterInterface> BucketAndObjectOperationTest::Limiter(nullptr);

TEST_F(BucketAndObjectOperationTest, TestInterrupt)
{
const Aws::String fullBucketName = CalculateBucketName(BASE_INTERRUPT_TESTING_BUCKET.c_str());
Expand All @@ -680,7 +677,7 @@ namespace
AWS_ASSERT_SUCCESS(createBucketOutcome);
const CreateBucketResult& createBucketResult = createBucketOutcome.GetResult();
ASSERT_TRUE(!createBucketResult.GetLocation().empty());
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
Expand Down Expand Up @@ -750,7 +747,7 @@ namespace
AWS_ASSERT_SUCCESS(createBucketOutcome);
const CreateBucketResult& createBucketResult = createBucketOutcome.GetResult();
ASSERT_FALSE(createBucketResult.GetLocation().empty());
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

ListBucketsOutcome listBucketsOutcome = Client->ListBuckets();
Expand Down Expand Up @@ -818,7 +815,7 @@ namespace
AWS_ASSERT_SUCCESS(createBucketOutcome);
const CreateBucketResult& createBucketResult = createBucketOutcome.GetResult();
ASSERT_TRUE(!createBucketResult.GetLocation().empty());
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
Expand All @@ -844,7 +841,7 @@ namespace
AWS_ASSERT_SUCCESS(createBucketOutcome);
const CreateBucketResult& createBucketResult = createBucketOutcome.GetResult();
ASSERT_TRUE(!createBucketResult.GetLocation().empty());
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

Aws::Vector<Aws::String> objectKeysWithNewlineCharacter;
Expand Down Expand Up @@ -913,7 +910,7 @@ namespace
AWS_ASSERT_SUCCESS(createBucketOutcome);
const CreateBucketResult& createBucketResult = createBucketOutcome.GetResult();
ASSERT_TRUE(!createBucketResult.GetLocation().empty());
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
Expand Down Expand Up @@ -1000,7 +997,7 @@ namespace
AWS_ASSERT_SUCCESS(createBucketOutcome);
const CreateBucketResult& createBucketResult = createBucketOutcome.GetResult();
ASSERT_TRUE(!createBucketResult.GetLocation().empty());
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

//test unicode
Expand Down Expand Up @@ -1171,7 +1168,7 @@ namespace
AWS_ASSERT_SUCCESS(createBucketOutcome);
const CreateBucketResult& createBucketResult = createBucketOutcome.GetResult();
ASSERT_TRUE(!createBucketResult.GetLocation().empty());
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

CreateMultipartUploadRequest createMultipartUploadRequest;
Expand Down Expand Up @@ -1406,7 +1403,7 @@ namespace

CreateBucketOutcome createBucketOutcome = Client->CreateBucket(createBucketRequest);
AWS_ASSERT_SUCCESS(createBucketOutcome);
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

GetObjectRequest getObjectRequest;
Expand All @@ -1430,7 +1427,7 @@ namespace
createBucketRequest.SetACL(BucketCannedACL::private_);
CreateBucketOutcome createBucketOutcome = Client->CreateBucket(createBucketRequest);
AWS_ASSERT_SUCCESS(createBucketOutcome);
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
Expand Down Expand Up @@ -1466,7 +1463,7 @@ namespace
createBucketRequest.SetACL(BucketCannedACL::private_);
CreateBucketOutcome createBucketOutcome = Client->CreateBucket(createBucketRequest);
AWS_ASSERT_SUCCESS(createBucketOutcome);
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
Expand Down Expand Up @@ -1496,7 +1493,7 @@ namespace
createBucketRequest.SetACL(BucketCannedACL::private_);
CreateBucketOutcome createBucketOutcome = Client->CreateBucket(createBucketRequest);
AWS_ASSERT_SUCCESS(createBucketOutcome);
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

auto objectStream = Aws::MakeShared<Aws::StringStream>("BucketAndObjectOperationTest");
Expand Down Expand Up @@ -1532,7 +1529,7 @@ namespace
createBucketRequest.SetObjectLockEnabledForBucket(true);
CreateBucketOutcome createBucketOutcome = Client->CreateBucket(createBucketRequest);
AWS_ASSERT_SUCCESS(createBucketOutcome);
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
Expand Down Expand Up @@ -1578,7 +1575,7 @@ namespace
createBucketRequest.SetACL(BucketCannedACL::private_);
CreateBucketOutcome createBucketOutcome = Client->CreateBucket(createBucketRequest);
AWS_ASSERT_SUCCESS(createBucketOutcome);
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
Expand Down Expand Up @@ -1656,7 +1653,7 @@ namespace
createBucketRequest.SetACL(BucketCannedACL::private_);
CreateBucketOutcome createBucketOutcome = Client->CreateBucket(createBucketRequest);
AWS_ASSERT_SUCCESS(createBucketOutcome);
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
Expand Down Expand Up @@ -1731,7 +1728,7 @@ namespace
createBucketRequest.SetACL(BucketCannedACL::private_);
CreateBucketOutcome createBucketOutcome = Client->CreateBucket(createBucketRequest);
AWS_ASSERT_SUCCESS(createBucketOutcome);
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
Expand Down Expand Up @@ -1837,7 +1834,7 @@ namespace
createBucketRequest.SetACL(BucketCannedACL::private_);
CreateBucketOutcome createBucketOutcome = Client->CreateBucket(createBucketRequest);
AWS_ASSERT_SUCCESS(createBucketOutcome);
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
Expand Down Expand Up @@ -1992,7 +1989,7 @@ namespace

CreateBucketOutcome createBucketOutcome = Client->CreateBucket(createBucketRequest);
AWS_ASSERT_SUCCESS(createBucketOutcome);
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

CreateMultipartUploadRequest createMultipartUploadRequest;
Expand Down Expand Up @@ -2399,7 +2396,7 @@ namespace
AWS_ASSERT_SUCCESS(createBucketOutcome);
const CreateBucketResult& createBucketResult = createBucketOutcome.GetResult();
ASSERT_TRUE(!createBucketResult.GetLocation().empty());
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
Expand Down
16 changes: 1 addition & 15 deletions tests/aws-cpp-sdk-s3-integration-tests/RunTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,14 @@
* SPDX-License-Identifier: Apache-2.0.
*/

#include <gtest/gtest.h>
#include <aws/core/Aws.h>
#include <aws/testing/platform/PlatformTesting.h>
#include <aws/testing/AwsCppSdkGTestSuite.h>
#include <aws/testing/TestingEnvironment.h>
#include <aws/testing/MemoryTesting.h>

int main(int argc, char** argv)
{
Aws::Testing::SetDefaultSigPipeHandler();
Aws::SDKOptions options;
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;
AWS_BEGIN_MEMORY_TEST_EX(options, 1024, 128);

Aws::Testing::InitPlatformTest(options);
Aws::Testing::ParseArgs(argc, argv);

Aws::InitAPI(options);
::testing::InitGoogleTest(&argc, argv);
int exitCode = RUN_ALL_TESTS();

Aws::ShutdownAPI(options);
AWS_END_MEMORY_TEST_EX;
Aws::Testing::ShutdownPlatformTest(options);
return exitCode;
}
4 changes: 2 additions & 2 deletions tests/aws-cpp-sdk-s3-integration-tests/S3ExpressTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0.
*/

#include <gtest/gtest.h>
#include <aws/testing/AwsCppSdkGTestSuite.h>
#include <aws/testing/AwsTestHelpers.h>
#include <aws/core/platform/Environment.h>
#include <aws/core/http/HttpResponse.h>
Expand Down Expand Up @@ -53,7 +53,7 @@ namespace {
const char* ALLOCATION_TAG = "S3ClientS3ExpressTest";
const char* S3_EXPRESS_SUFFIX = "--use1-az6--x-s3";

class S3ExpressTest : public ::testing::Test {
class S3ExpressTest : public Aws::Testing::AwsCppSdkGTestSuite {
public:
CreateBucketOutcome CreateBucket(const Aws::String &bucketName = randomString() + S3_EXPRESS_SUFFIX) {
bucketsToCleanup.push_back(bucketName);
Expand Down

0 comments on commit 632885a

Please sign in to comment.