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

Mock s3 test #231

merged 43 commits into from
Dec 7, 2022

Conversation

TingDaoK
Copy link
Contributor

@TingDaoK TingDaoK commented Nov 14, 2022

Issue #, if available:

  • We lack of ability to test error cases, as we don't have a mock S3 server

Description of changes:

  • Added a mock S3 server framework that support multipart upload for now.

TODO:

  • supports all the type of request we made.
  • add helper for test to write the response during runtime.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@TingDaoK TingDaoK marked this pull request as ready for review November 15, 2022 00:19
Comment on lines 181 to 187
python3 -m pip install h11 trio
- name: Build ${{ env.PACKAGE_NAME }}
run: |
cd ./tests/mock_s3_server/
Start-Process -NoNewWindow python .\mock_s3_server.py
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
python3 builder.pyz build -p ${{ env.PACKAGE_NAME }} --cmake-extra=-DENABLE_MOCK_SERVER_TESTS=ON
Copy link
Contributor

Choose a reason for hiding this comment

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

debatable: we could try to set up the mock server in EVERY CI check (instead of just these 3) if we set it up via a custom builder script.

This is how I did PKCS#11 tests. Check out aws-c-io/.builder/actions/pkcs11_test_setup.py. It tries to install dependencies, and sets the appropriate environment variables to run the tests if it succeeds (if it can't install the dependencies, then it just spits out a warning and doesn't set the environment variables). You can launch the background process via subprocess.Popen()

Comment on lines 20 to 21
/* Test that the remote max concurrent streams setting hit */
TEST_CASE(multipart_upload_mock_server) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this is a "success" test, but comment says something about "max concurrent streams"

Comment on lines 29 to 30
print("Mock server failed to setup, skip the mock server tests.")
return
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure which is better, error out or return..

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it failing to install anywhere? If it works everywhere, then make it an error

If we just return: there's a chance that setup starts failing everywhere, but we never realize because it's a silent warning

If we make it an error: then you can end up spending waaaaay too much time trying to get it working on esoteric/old platforms like manylinux1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

current it's not failing from anywhere. But, two weeks ago, I think github ubuntu 20 image was failing to install trio for "I don't know" reason. Let's make it fail and heck around the image that doesn't support it.

Comment on lines 20 to 27
if os.name == 'nt':
python_execute = "python"
else:
python_execute = "python3"

# install dependency for mock server
result = self.env.shell.exec(python_execute,
'-m', 'install', 'h11', 'trio')
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the string "{python}"
Builder will substitute the correct python path for this image

.builder/actions/mock_server_setup.py Outdated Show resolved Hide resolved
Comment on lines 26 to 29
if result.returncode != 0:
print(
"Mock server failed to setup, skip the mock server tests.", file=sys.stderr)
exit(-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

you can do self.env.shell.exec(..., check=True)

and then you don't need to add any extra code for checking the return code


def run(self, env):
self.env = env
python_path = env.config['variables'].get('python')
Copy link
Contributor

Choose a reason for hiding this comment

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

you had good luck using sys.executable instead here

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

Choose a reason for hiding this comment

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

neato

@TingDaoK TingDaoK merged commit 3cd5402 into main Dec 7, 2022
@TingDaoK TingDaoK deleted the mock-s3-test branch December 7, 2022 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants