Improved lambda timings
This commit is contained in:
parent
9ddf7fe436
commit
62a2d8f756
@ -298,7 +298,12 @@ class LambdaFunction(BaseModel):
|
|||||||
volumes=["{}:/var/task".format(data_vol.name)], environment=env_vars, detach=True, **run_kwargs)
|
volumes=["{}:/var/task".format(data_vol.name)], environment=env_vars, detach=True, **run_kwargs)
|
||||||
finally:
|
finally:
|
||||||
if container:
|
if container:
|
||||||
exit_code = container.wait()
|
try:
|
||||||
|
exit_code = container.wait(timeout=300)
|
||||||
|
except requests.exceptions.ReadTimeout:
|
||||||
|
exit_code = -1
|
||||||
|
container.stop()
|
||||||
|
container.kill()
|
||||||
output = container.logs(stdout=False, stderr=True)
|
output = container.logs(stdout=False, stderr=True)
|
||||||
output += container.logs(stdout=True, stderr=False)
|
output += container.logs(stdout=True, stderr=False)
|
||||||
container.remove()
|
container.remove()
|
||||||
|
@ -12,6 +12,24 @@ except:
|
|||||||
from moto.core.utils import amz_crc32, amzn_request_id
|
from moto.core.utils import amz_crc32, amzn_request_id
|
||||||
from moto.core.responses import BaseResponse
|
from moto.core.responses import BaseResponse
|
||||||
|
|
||||||
|
import signal
|
||||||
|
import contextlib
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def timeout(seconds=5):
|
||||||
|
def handle_error(signum, frame):
|
||||||
|
raise RuntimeError()
|
||||||
|
|
||||||
|
try:
|
||||||
|
signal.signal(signal.SIGALRM, handle_error)
|
||||||
|
signal.alarm(seconds)
|
||||||
|
yield None
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
signal.alarm(0)
|
||||||
|
|
||||||
|
|
||||||
class LambdaResponse(BaseResponse):
|
class LambdaResponse(BaseResponse):
|
||||||
|
|
||||||
@ -100,6 +118,7 @@ class LambdaResponse(BaseResponse):
|
|||||||
|
|
||||||
if lambda_backend.has_function(function_name):
|
if lambda_backend.has_function(function_name):
|
||||||
fn = lambda_backend.get_function(function_name)
|
fn = lambda_backend.get_function(function_name)
|
||||||
|
with timeout(seconds=360):
|
||||||
payload = fn.invoke(self.body, self.headers, response_headers)
|
payload = fn.invoke(self.body, self.headers, response_headers)
|
||||||
response_headers['Content-Length'] = str(len(payload))
|
response_headers['Content-Length'] = str(len(payload))
|
||||||
return 202, response_headers, payload
|
return 202, response_headers, payload
|
||||||
@ -114,6 +133,7 @@ class LambdaResponse(BaseResponse):
|
|||||||
function_name = path.split('/')[-3]
|
function_name = path.split('/')[-3]
|
||||||
if lambda_backend.has_function(function_name):
|
if lambda_backend.has_function(function_name):
|
||||||
fn = lambda_backend.get_function(function_name)
|
fn = lambda_backend.get_function(function_name)
|
||||||
|
with timeout(seconds=360):
|
||||||
fn.invoke(self.body, self.headers, response_headers)
|
fn.invoke(self.body, self.headers, response_headers)
|
||||||
response_headers['Content-Length'] = str(0)
|
response_headers['Content-Length'] = str(0)
|
||||||
return 202, response_headers, ""
|
return 202, response_headers, ""
|
||||||
|
@ -488,6 +488,7 @@ def lambda_handler(event, context):
|
|||||||
assert 'FunctionError' in result
|
assert 'FunctionError' in result
|
||||||
assert result['FunctionError'] == 'Handled'
|
assert result['FunctionError'] == 'Handled'
|
||||||
|
|
||||||
|
|
||||||
@mock_lambda
|
@mock_lambda
|
||||||
@mock_s3
|
@mock_s3
|
||||||
def test_tags():
|
def test_tags():
|
||||||
@ -554,6 +555,7 @@ def test_tags():
|
|||||||
TagKeys=['spam']
|
TagKeys=['spam']
|
||||||
)['ResponseMetadata']['HTTPStatusCode'].should.equal(204)
|
)['ResponseMetadata']['HTTPStatusCode'].should.equal(204)
|
||||||
|
|
||||||
|
|
||||||
@mock_lambda
|
@mock_lambda
|
||||||
def test_tags_not_found():
|
def test_tags_not_found():
|
||||||
"""
|
"""
|
||||||
@ -574,6 +576,7 @@ def test_tags_not_found():
|
|||||||
TagKeys=['spam']
|
TagKeys=['spam']
|
||||||
).should.throw(botocore.client.ClientError)
|
).should.throw(botocore.client.ClientError)
|
||||||
|
|
||||||
|
|
||||||
@mock_lambda
|
@mock_lambda
|
||||||
def test_invoke_async_function():
|
def test_invoke_async_function():
|
||||||
conn = boto3.client('lambda', 'us-west-2')
|
conn = boto3.client('lambda', 'us-west-2')
|
||||||
@ -581,10 +584,8 @@ def test_invoke_async_function():
|
|||||||
FunctionName='testFunction',
|
FunctionName='testFunction',
|
||||||
Runtime='python2.7',
|
Runtime='python2.7',
|
||||||
Role='test-iam-role',
|
Role='test-iam-role',
|
||||||
Handler='lambda_function.handler',
|
Handler='lambda_function.lambda_handler',
|
||||||
Code={
|
Code={'ZipFile': get_test_zip_file1()},
|
||||||
'ZipFile': get_test_zip_file1(),
|
|
||||||
},
|
|
||||||
Description='test lambda function',
|
Description='test lambda function',
|
||||||
Timeout=3,
|
Timeout=3,
|
||||||
MemorySize=128,
|
MemorySize=128,
|
||||||
@ -598,6 +599,7 @@ def test_invoke_async_function():
|
|||||||
|
|
||||||
success_result['Status'].should.equal(202)
|
success_result['Status'].should.equal(202)
|
||||||
|
|
||||||
|
|
||||||
@mock_lambda
|
@mock_lambda
|
||||||
@freeze_time('2015-01-01 00:00:00')
|
@freeze_time('2015-01-01 00:00:00')
|
||||||
def test_get_function_created_with_zipfile():
|
def test_get_function_created_with_zipfile():
|
||||||
@ -646,6 +648,7 @@ def test_get_function_created_with_zipfile():
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@mock_lambda
|
@mock_lambda
|
||||||
def add_function_permission():
|
def add_function_permission():
|
||||||
conn = boto3.client('lambda', 'us-west-2')
|
conn = boto3.client('lambda', 'us-west-2')
|
||||||
|
Loading…
Reference in New Issue
Block a user