-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from satyamsoni2211/feature/lambda_concurrency
Feature/lambda concurrency
- Loading branch information
Showing
16 changed files
with
428 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: testing-python-code | ||
on: | ||
push: | ||
branches: | ||
- "feature/**" | ||
pull_request: | ||
branches: | ||
- "feature/**" | ||
jobs: | ||
test-code: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v3 | ||
with: | ||
python-version: 3.9 | ||
- run: pip install awscli tox | ||
- run: aws configure set region us-west-2 | ||
- run: tox | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,5 @@ venv | |
tfplan.json | ||
build/ | ||
dist/ | ||
.vscode | ||
.tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-r requirements.txt | ||
pytest | ||
tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[pytest] | ||
console_output_style = progress | ||
python_files = test_*.py | ||
addopts = --capture=tee-sys -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.3 | ||
0.1.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-i https://pypi.org/simple | ||
boto3==1.24.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from warmer import warmer | ||
from unittest import TestCase | ||
from unittest.mock import patch, Mock | ||
|
||
|
||
@warmer(_concurrency=5) | ||
def fake_wsgi(*args, **kwargs): | ||
return "_response" | ||
|
||
|
||
@warmer() | ||
def fake_wsgi_with_concurrency_event(*args, **kwargs): | ||
return "_response" | ||
|
||
|
||
class TestWarmerFunction(TestCase): | ||
@patch("botocore.client.BaseClient._make_api_call") | ||
def test_warmer_concurrency(self, mock: Mock): | ||
# checking call for warmer event | ||
response = fake_wsgi({"warmer": True}, {}) | ||
mock.assert_called() | ||
self.assertEqual(mock.call_count, 4) | ||
self.assertIn("statusCode", response) | ||
|
||
@patch("botocore.client.BaseClient._make_api_call") | ||
def test_warmer_response_body(self, mock: Mock): | ||
# checking call for warmer event | ||
response = fake_wsgi({"warmer": True}, {}) | ||
self.assertIn("statusCode", response) | ||
self.assertIn("isBase64Encoded", response) | ||
body = response.get("body") | ||
self.assertIn("eventFlag", body) | ||
self.assertEqual("warmed up", body.get("status")) | ||
|
||
def test_wsgi_function_response(self): | ||
# testing call being passed to function on no warmer event | ||
self.assertAlmostEqual("_response", fake_wsgi({}, {})) | ||
|
||
@patch("warmer.call_function_concurrently") | ||
def test_concurrency_function_args(self, mock: Mock): | ||
# function should be passed with same flag | ||
# with is an indetifier for the | ||
# warming event | ||
fake_wsgi({"warmer": True}, {}) | ||
mock.assert_called() | ||
mock.assert_called_with(5, "warmer") | ||
|
||
@patch("botocore.client.BaseClient._make_api_call") | ||
def test_for_concurrency_using_event(self, mock: Mock): | ||
# function to check for concurrent calls when passed via event | ||
fake_wsgi_with_concurrency_event( | ||
{"warmer": True, "concurrency": 5}, {}) | ||
self.assertEqual(mock.call_count, 4) | ||
|
||
@patch("botocore.client.BaseClient._make_api_call") | ||
def test_for_concurrency_using_default_event(self, mock: Mock): | ||
# No concurrent calls should be made in case | ||
# of concurrency = 1 | ||
fake_wsgi_with_concurrency_event( | ||
{"warmer": True}, {}) | ||
self.assertEqual(mock.call_count, 0) | ||
mock.assert_not_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[tox] | ||
envlist = python3.6,python3.7,python3.8,python3.9 | ||
|
||
[testenv] | ||
# install pytest in the virtualenv where commands will be executed | ||
deps = | ||
pytest | ||
boto3 | ||
|
||
commands = | ||
# NOTE: you can run any command line tool here - not just tests | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters