Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock s3 test #231

Merged
merged 43 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9fc335e
mock server test
TingDaoK Nov 14, 2022
b22af9a
add it to CO
TingDaoK Nov 14, 2022
569ab8e
fix the test
TingDaoK Nov 14, 2022
4dd231c
Merge branch 'main' into mock-s3-test
TingDaoK Nov 14, 2022
2dab4cc
format error
TingDaoK Nov 14, 2022
cc0a8cf
remove non-used import
TingDaoK Nov 14, 2022
ce35d84
missing -D
TingDaoK Nov 14, 2022
16062ac
update the windows one
TingDaoK Nov 14, 2022
12d2d18
why
TingDaoK Nov 14, 2022
9c305c5
accident
TingDaoK Nov 14, 2022
2a1bf09
extra line copied
TingDaoK Nov 14, 2022
d8fcccc
doesn't make sense
TingDaoK Nov 14, 2022
5f78137
what about the latest?
TingDaoK Nov 14, 2022
4c47712
handle different path
TingDaoK Nov 14, 2022
273149d
fix the path and add default
TingDaoK Nov 14, 2022
898fd7e
report the internal error case
TingDaoK Nov 14, 2022
6736f3c
get it ready for review
TingDaoK Nov 14, 2022
b1ff3ff
more test
TingDaoK Nov 15, 2022
f9f6e21
add readme and stuff
TingDaoK Nov 15, 2022
da67c11
I don't know
TingDaoK Nov 15, 2022
42ecec8
try to see if it's because the ubuntu version
TingDaoK Nov 15, 2022
7275878
try 18.04
TingDaoK Nov 15, 2022
7084d69
what about using container
TingDaoK Nov 15, 2022
ea32977
18
TingDaoK Nov 15, 2022
9cf7b8b
It probably not matters
TingDaoK Nov 15, 2022
577e358
remove not used line
TingDaoK Nov 15, 2022
d0fbc08
Merge branch 'main' into mock-s3-test
TingDaoK Nov 28, 2022
d3f076e
seems working
TingDaoK Dec 2, 2022
05d25fa
ops..
TingDaoK Dec 2, 2022
ba68502
exit if install failed
TingDaoK Dec 2, 2022
22ce005
exit when failed
TingDaoK Dec 2, 2022
c6fa19e
skip mock server test sliently?
TingDaoK Dec 2, 2022
1df2327
remove special CI
TingDaoK Dec 2, 2022
28fe75c
remove copy/pasted comment
TingDaoK Dec 5, 2022
3f5e699
Merge branch 'main' into mock-s3-test
TingDaoK Dec 5, 2022
2f70eb2
use {python}?
TingDaoK Dec 5, 2022
c537d24
Merge branch 'mock-s3-test' of github.com:awslabs/aws-c-s3 into mock-…
TingDaoK Dec 5, 2022
1d6f882
KEYS?
TingDaoK Dec 5, 2022
b2e1f38
data.keys?
TingDaoK Dec 5, 2022
c553c2a
env.config["python"]
TingDaoK Dec 5, 2022
94c3322
finally
TingDaoK Dec 5, 2022
a233c25
return op_success instead
TingDaoK Dec 5, 2022
c01875f
comment addresed
TingDaoK Dec 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .builder/actions/mock_server_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Setup local mock server for tests
"""

import Builder

import os
import sys
import subprocess
import atexit


class MockServerSetup(Builder.Action):
"""
Set up this machine for running the mock server test

This action should be run in the 'pre_build_steps' or 'build_steps' stage.
"""

def run(self, env):
self.env = env
python_path = sys.executable
# install dependency for mock server
self.env.shell.exec(python_path,
'-m', 'pip', 'install', 'h11', 'trio', check=True)
# check the deps can be import correctly
self.env.shell.exec(python_path,
'-c', 'import h11, trio', check=True)

# set cmake flag so mock server tests are enabled
env.project.config['cmake_args'].append(
'-DENABLE_MOCK_SERVER_TESTS=ON')

base_dir = os.path.dirname(os.path.realpath(__file__))
dir = os.path.join(base_dir, "..", "..", "tests", "mock_s3_server")
os.chdir(dir)

p = subprocess.Popen([python_path, "mock_s3_server.py"])

@atexit.register
def close_mock_server():
p.terminate()
Comment on lines +40 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neato

2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if (POLICY CMP0069)
endif()

option(ASSERT_LOCK_HELD "Enable ASSERT_SYNCED_DATA_LOCK_HELD for checking thread issue" OFF)
option(ENABLE_MOCK_SERVER_TESTS "Whether to run the integration tests that rely on pre-configured mock server" OFF)

if (ASSERT_LOCK_HELD)
add_definitions(-DASSERT_LOCK_HELD)
endif()
Expand Down
3 changes: 2 additions & 1 deletion builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
],
"test_steps": [
"test"
]
],
"pre_build_steps": ["mock-server-setup"]
}
4 changes: 3 additions & 1 deletion source/s3_meta_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ void aws_s3_meta_request_set_fail_synced(

meta_request->synced_data.finish_result_set = true;

if (error_code == AWS_ERROR_S3_INVALID_RESPONSE_STATUS && failed_request != NULL) {
if ((error_code == AWS_ERROR_S3_INVALID_RESPONSE_STATUS ||
error_code == AWS_ERROR_S3_NON_RECOVERABLE_ASYNC_ERROR) &&
failed_request != NULL) {
aws_s3_meta_request_result_setup(
meta_request,
&meta_request->synced_data.finish_result,
Expand Down
7 changes: 7 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,12 @@ add_test_case(test_s3_list_bucket_init_mem_safety)
add_test_case(test_s3_list_bucket_init_mem_safety_optional_copies)
add_net_test_case(test_s3_list_bucket_valid)

# Tests against local mock server
if (ENABLE_MOCK_SERVER_TESTS)
add_net_test_case(multipart_upload_mock_server)
add_net_test_case(async_internal_error_from_complete_multipart_mock_server)
add_net_test_case(async_access_denied_from_complete_multipart_mock_server)
endif()

set(TEST_BINARY_NAME ${PROJECT_NAME}-tests)
generate_test_driver(${TEST_BINARY_NAME})
6 changes: 6 additions & 0 deletions tests/mock_s3_server/AbortMultipartUpload/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"status": 204,
"headers": {"Connection": "keep-alive"},
"body": [
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"status": 200,
"headers": {"Connection": "close"},
"body": [
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"",
"<Error>",
"<Code>AccessDenied</Code>",
"<Message>Access denied.</Message>",
"<RequestId>656c76696e6727732072657175657374</RequestId>",
"<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>",
"</Error>"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"status": 200,
"headers": {"Connection": "close"},
"body": [
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"",
"<Error>",
"<Code>InternalError</Code>",
"<Message>We encountered an internal error. Please try again.</Message>",
"<RequestId>656c76696e6727732072657175657374</RequestId>",
"<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>",
"</Error>"
]
}
13 changes: 13 additions & 0 deletions tests/mock_s3_server/CompleteMultipartUpload/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"status": 200,
"headers": {"Connection": "close"},
"body": [
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"<CompleteMultipartUploadResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">",
"<Location>http://default.s3.us-west-2.amazonaws.com/default</Location>",
"<Bucket>default</Bucket>",
"<Key>default</Key>",
"<ETag>\"3858f62230ac3c915f300c664312c11f-9\"</ETag>",
"</CompleteMultipartUploadResult>"
]
}
12 changes: 12 additions & 0 deletions tests/mock_s3_server/CreateMultipartUpload/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"status": 200,
"headers": {},
"body": [
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"<InitiateMultipartUploadResult>",
"<Bucket>default</Bucket>",
"<Key>default</Key>",
"<UploadId>defaultID</UploadId>",
"</InitiateMultipartUploadResult>"
]
}
40 changes: 40 additions & 0 deletions tests/mock_s3_server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Mock S3 server

A **NON-TLS** mock S3 server based on [python-hyper/h11](https://github.com/python-hyper/h11) and [trio](http://trio.readthedocs.io/en/latest/index.html). The server code implementation is based on the trio-server example from python-hyper/h11 [here](https://github.com/python-hyper/h11/blob/master/examples/trio-server.py). Only supports very basic mock response for request received.

## How to run the server

Python 3.5+ required.

- Install hyper/h11 and trio python module. `python3 -m pip install h11 trio`
- Run python. `python3 ./mock_s3_server.py`.

### Supported Operations

- CreateMultipartUpload
- CompleteMultipartUpload
- UploadPart
- AbortMultipartUpload

### Defined response

The server will read from ./{OperationName}/{Key}.json. The json file is formatted as following:

```json
{
"status": 200,
"headers": {"Connection": "close"},
"body": [
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"",
"<Error>",
"<Code>InternalError</Code>",
"<Message>We encountered an internal error. Please try again.</Message>",
"<RequestId>656c76696e6727732072657175657374</RequestId>",
"<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>",
"</Error>"
]
}
```

Where you can define the expected response status, header and response body. If the {Key}.json is not found from file system, it will load the `default.json`.
6 changes: 6 additions & 0 deletions tests/mock_s3_server/UploadPart/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"status": 200,
"headers": {"ETag": "b54357faf0632cce46e942fa68356b38", "Connection": "keep-alive"},
"body": [
]
}
Loading