Skip to content

Commit

Permalink
Bump Lambda runtime versions and increase sleep time (#10698)
Browse files Browse the repository at this point in the history
  • Loading branch information
joe4dev committed Apr 23, 2024
1 parent 720c4d7 commit 536cc28
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tests/aws/services/lambda_/test_lambda_developer_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class TestHotReloading:
@pytest.mark.parametrize(
"runtime,handler_file,handler_filename",
[
(Runtime.nodejs18_x, HOT_RELOADING_NODEJS_HANDLER, "handler.mjs"),
(Runtime.python3_9, HOT_RELOADING_PYTHON_HANDLER, "handler.py"),
(Runtime.nodejs20_x, HOT_RELOADING_NODEJS_HANDLER, "handler.mjs"),
(Runtime.python3_12, HOT_RELOADING_PYTHON_HANDLER, "handler.py"),
],
ids=["nodejs18.x", "python3.9"],
ids=["nodejs20.x", "python3.12"],
)
@markers.aws.only_localstack
def test_hot_reloading(
Expand All @@ -45,6 +45,9 @@ def test_hot_reloading(
aws_client,
):
"""Test hot reloading of lambda code"""
# Hot reloading is debounced with 500ms
# 0.6 works on Linux, but it takes slightly longer on macOS
sleep_time = 0.8
function_name = f"test-hot-reloading-{short_uid()}"
hot_reloading_bucket = config.BUCKET_MARKER_LOCAL
tmp_path = config.dirs.mounted_tmp
Expand Down Expand Up @@ -74,7 +77,7 @@ def test_hot_reloading(
with open(os.path.join(hot_reloading_dir_path, handler_filename), mode="wt") as f:
f.write(function_content.replace("value1", "value2"))
# we have to sleep here, since the hot reloading is debounced with 500ms
time.sleep(0.6)
time.sleep(sleep_time)
response = aws_client.lambda_.invoke(FunctionName=function_name, Payload=b"{}")
response_dict = json.load(response["Payload"])
assert response_dict["counter"] == 1
Expand All @@ -88,15 +91,15 @@ def test_hot_reloading(
test_folder = os.path.join(hot_reloading_dir_path, "test-folder")
mkdir(test_folder)
# make sure the creation of the folder triggered reload
time.sleep(0.6)
time.sleep(sleep_time)
response = aws_client.lambda_.invoke(FunctionName=function_name, Payload=b"{}")
response_dict = json.load(response["Payload"])
assert response_dict["counter"] == 1
assert response_dict["constant"] == "value2"
# now writing something in the new folder to check if it will reload
with open(os.path.join(test_folder, "test-file"), mode="wt") as f:
f.write("test-content")
time.sleep(0.6)
time.sleep(sleep_time)
response = aws_client.lambda_.invoke(FunctionName=function_name, Payload=b"{}")
response_dict = json.load(response["Payload"])
assert response_dict["counter"] == 1
Expand Down Expand Up @@ -128,7 +131,7 @@ def test_hot_reloading_publish_version(
Handler="handler.handler",
Code={"S3Bucket": hot_reloading_bucket, "S3Key": mount_path},
Role=lambda_su_role,
Runtime=Runtime.nodejs18_x,
Runtime=Runtime.nodejs20_x,
)
aws_client.lambda_.publish_version(FunctionName=function_name, CodeSha256="zipfilehash")

Expand All @@ -143,7 +146,7 @@ def test_additional_docker_flags(self, create_lambda_function, monkeypatch, aws_
create_lambda_function(
handler_file=TEST_LAMBDA_ENV,
func_name=function_name,
runtime=Runtime.python3_9,
runtime=Runtime.python3_12,
)
aws_client.lambda_.get_waiter("function_active_v2").wait(FunctionName=function_name)
result = aws_client.lambda_.invoke(FunctionName=function_name, Payload="{}")
Expand Down Expand Up @@ -180,13 +183,13 @@ def _delete_network():
zip_file = create_lambda_archive(
load_file(LAMBDA_NETWORKS_PYTHON_HANDLER),
get_content=True,
runtime=Runtime.python3_9,
runtime=Runtime.python3_12,
)
aws_client.lambda_.create_function(
FunctionName=function_name,
Code={"ZipFile": zip_file},
Handler="handler.handler",
Runtime=Runtime.python3_9,
Runtime=Runtime.python3_12,
Role=lambda_su_role,
)
cleanups.append(lambda: aws_client.lambda_.delete_function(FunctionName=function_name))
Expand All @@ -212,7 +215,7 @@ def test_lambda_localhost_localstack_cloud_connectivity(
create_lambda_function(
handler_file=LAMBDA_NETWORKS_PYTHON_HANDLER,
func_name=function_name,
runtime=Runtime.python3_11,
runtime=Runtime.python3_12,
)

result = aws_client.lambda_.invoke(
Expand Down

0 comments on commit 536cc28

Please sign in to comment.