|
1 | | -#include <gtest/gtest.h> |
2 | 1 | #include <aws/core/Aws.h> |
3 | 2 | #include <aws/core/auth/AWSCredentials.h> |
4 | 3 | #include <aws/core/client/RetryStrategy.h> |
5 | 4 | #include <aws/core/utils/HashingUtils.h> |
6 | 5 | #include <aws/core/utils/base64/Base64.h> |
7 | 6 | #include <aws/core/utils/crypto/CRC64.h> |
8 | 7 | #include <aws/s3/S3Client.h> |
| 8 | +#include <aws/s3/S3ErrorMarshaller.h> |
| 9 | +#include <aws/s3/model/CopyObjectRequest.h> |
9 | 10 | #include <aws/s3/model/DeleteObjectsRequest.h> |
| 11 | +#include <aws/s3/model/GetObjectRequest.h> |
| 12 | +#include <aws/s3/model/HeadBucketRequest.h> |
| 13 | +#include <aws/s3/model/ListObjectsV2Request.h> |
10 | 14 | #include <aws/s3/model/PutObjectRequest.h> |
11 | | -#include <aws/s3/model/CopyObjectRequest.h> |
12 | | -#include <aws/testing/mocks/http/MockHttpClient.h> |
13 | 15 | #include <aws/testing/AwsTestHelpers.h> |
14 | 16 | #include <aws/testing/MemoryTesting.h> |
| 17 | +#include <aws/testing/mocks/http/MockHttpClient.h> |
| 18 | +#include <gtest/gtest.h> |
| 19 | + |
15 | 20 | #include <memory> |
16 | | -#include <aws/s3/S3ErrorMarshaller.h> |
17 | | -#include <aws/s3/model/HeadBucketRequest.h> |
18 | | -#include <aws/s3/model/ListObjectsV2Request.h> |
19 | 21 |
|
20 | 22 | using namespace Aws; |
21 | 23 | using namespace Aws::Client; |
@@ -705,3 +707,22 @@ TEST_F(S3UnitTest, ListObjectsV2PaginatorShouldHaveCMetric) { |
705 | 707 | [](const Aws::String& value) { return value.find("m/") != Aws::String::npos && value.find("C") != Aws::String::npos; }); |
706 | 708 | EXPECT_TRUE(businessMetrics != userAgentParsed.end()); |
707 | 709 | } |
| 710 | + |
| 711 | +TEST_F(S3UnitTest, TestGetObjectTimeoutShouldReturnTimeoutError) { |
| 712 | + auto request = GetObjectRequest().WithBucket("test-bucket").WithKey("test-key"); |
| 713 | + |
| 714 | + auto mockRequest = Aws::MakeShared<Standard::StandardHttpRequest>(ALLOCATION_TAG, "test-bucket.s3.amazonaws.com/", HttpMethod::HTTP_GET); |
| 715 | + mockRequest->SetResponseStreamFactory( |
| 716 | + []() -> IOStream* { return Aws::New<StringStream>(ALLOCATION_TAG, "", std::ios_base::in | std::ios_base::binary); }); |
| 717 | + auto mockResponse = Aws::MakeShared<Standard::StandardHttpResponse>(ALLOCATION_TAG, mockRequest); |
| 718 | + mockResponse->SetResponseCode(HttpResponseCode::NETWORK_CONNECT_TIMEOUT); |
| 719 | + mockResponse->AddHeader("x-amz-checksum-crc32", "1f2e4daa"); |
| 720 | + _mockHttpClient->AddResponseToReturn(mockResponse, |
| 721 | + [](Aws::IOStream& response) -> void { response << "The distance between what is said"; }); |
| 722 | + |
| 723 | + const auto response = _s3Client->GetObject(request); |
| 724 | + EXPECT_FALSE(response.IsSuccess()); |
| 725 | + const auto& error = response.GetError(); |
| 726 | + EXPECT_EQ(error.GetResponseCode(), HttpResponseCode::NETWORK_CONNECT_TIMEOUT); |
| 727 | + EXPECT_TRUE(error.ShouldRetry()); |
| 728 | +} |
0 commit comments