Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fe11d78

Browse files
authoredApr 19, 2024
test: Refactor test cases (#119)
Refactor testcases to - Use python3.12 - Respect docker architecture - Run different architecture in parallel GitHub actions
1 parent 4c2c20d commit fe11d78

File tree

4 files changed

+211
-149
lines changed

4 files changed

+211
-149
lines changed
 

‎.github/workflows/integ-tests.yml

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,44 @@ on:
66
- develop
77

88
jobs:
9-
integ-tests:
9+
go-tests:
1010
runs-on: ubuntu-latest
1111
environment:
12-
name: prod
12+
name: integ-tests
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: run go tests
16+
run: make tests-with-docker
17+
integ-tests-x86:
18+
runs-on: ubuntu-latest
19+
environment:
20+
name: integ-tests
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.11'
26+
- name: run integration tests
27+
run: make integ-tests-with-docker-x86-64
28+
integ-tests-arm64:
29+
runs-on: ubuntu-latest
30+
environment:
31+
name: integ-tests
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: actions/setup-python@v5
35+
with:
36+
python-version: '3.11'
37+
- name: run integration tests
38+
run: make integ-tests-with-docker-arm64
39+
integ-tests-old:
40+
runs-on: ubuntu-latest
41+
environment:
42+
name: integ-tests
1343
steps:
1444
- uses: actions/checkout@v4
1545
- uses: actions/setup-python@v5
1646
with:
1747
python-version: '3.11'
18-
- name: allows us to build arm64 images
19-
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
2048
- name: run integration tests
21-
run: make integ-tests-with-docker
49+
run: make integ-tests-with-docker-old

‎Makefile

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,35 @@ integ-tests-and-compile: tests
3939
integ-tests-with-docker: tests-with-docker
4040
make compile-with-docker-all
4141
make integ-tests
42-
43-
integ-tests:
42+
43+
prep-python:
4444
python3 -m venv .venv
4545
.venv/bin/pip install --upgrade pip
4646
.venv/bin/pip install requests parameterized
47+
48+
exec-python-e2e-test:
4749
.venv/bin/python3 test/integration/local_lambda/test_end_to_end.py
50+
51+
integ-tests:
52+
make prep-python
53+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
54+
make TEST_ARCH=x86_64 TEST_PORT=8002 exec-python-e2e-test
55+
make TEST_ARCH=arm64 TEST_PORT=9002 exec-python-e2e-test
56+
make TEST_ARCH="" TEST_PORT=9052 exec-python-e2e-test
57+
58+
integ-tests-with-docker-x86-64:
59+
make ARCH=x86_64 compile-with-docker
60+
make prep-python
61+
make TEST_ARCH=x86_64 TEST_PORT=8002 exec-python-e2e-test
62+
63+
integ-tests-with-docker-arm64:
64+
make ARCH=arm64 compile-with-docker
65+
make prep-python
66+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
67+
make TEST_ARCH=arm64 TEST_PORT=9002 exec-python-e2e-test
68+
69+
integ-tests-with-docker-old:
70+
make ARCH=old compile-with-docker
71+
make prep-python
72+
make TEST_ARCH="" TEST_PORT=9052 exec-python-e2e-test
73+

‎test/integration/local_lambda/test_end_to_end.py

Lines changed: 148 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -5,227 +5,234 @@
55
from unittest import TestCase, main
66
from pathlib import Path
77
import time
8-
8+
import os
99
import requests
10+
from contextlib import contextmanager
1011
from parameterized import parameterized
1112

12-
SLEEP_TIME = 2
13+
SLEEP_TIME = 1.5
1314
DEFAULT_1P_ENTRYPOINT = "/lambda-entrypoint.sh"
1415
ARCHS = ["x86_64", "arm64", ""]
1516

1617

18+
1719
class TestEndToEnd(TestCase):
20+
ARCH = os.environ.get('TEST_ARCH', "")
21+
PORT = os.environ.get('TEST_PORT', 8002)
1822
@classmethod
1923
def setUpClass(cls):
2024
testdata_path = Path(__file__).resolve().parents[1].joinpath("testdata")
2125
dockerfile_path = testdata_path.joinpath("Dockerfile-allinone")
22-
cls.image_name = "aws-lambda-local:testing"
2326
cls.path_to_binary = Path().resolve().joinpath("bin")
2427

2528
# build image
26-
for arch in ARCHS:
27-
image_name = cls.image_name if arch == "" else f"{cls.image_name}-{arch}"
28-
architecture = arch if arch == "arm64" else "amd64"
29-
build_cmd = [
30-
"docker",
31-
"build",
32-
"--platform",
33-
f"linux/{architecture}",
34-
"-t",
35-
image_name,
36-
"-f",
37-
str(dockerfile_path),
38-
str(testdata_path),
39-
]
40-
Popen(build_cmd).communicate()
29+
image_name_base = "aws-lambda-local:testing"
30+
cls.image_name = image_name_base if cls.ARCH == "" else f"{image_name_base}-{cls.ARCH}"
31+
architecture = cls.ARCH if cls.ARCH == "arm64" else "amd64"
32+
docker_arch = cls.ARCH if cls.ARCH == "arm64" else "x86_64"
33+
34+
build_cmd = [
35+
"docker",
36+
"build",
37+
"--platform",
38+
f"linux/{architecture}",
39+
"-t",
40+
cls.image_name,
41+
"-f",
42+
str(dockerfile_path),
43+
str(testdata_path),
44+
"--build-arg",
45+
f"IMAGE_ARCH={docker_arch}",
46+
]
47+
Popen(build_cmd).communicate()
4148

4249
@classmethod
4350
def tearDownClass(cls):
44-
images_to_delete = [
45-
"envvarcheck",
46-
"twoinvokes",
47-
"arnexists",
48-
"customname",
49-
"timeout",
50-
"exception",
51-
"remaining_time_in_three_seconds",
52-
"remaining_time_in_ten_seconds",
53-
"remaining_time_in_default_deadline",
54-
"pre-runtime-api",
55-
"assert-overwritten",
56-
"port_override"
57-
]
58-
59-
for image in images_to_delete:
60-
for arch in ARCHS:
61-
arch_tag = "" if arch == "" else f"-{arch}"
62-
cmd = f"docker rm -f {image}{arch_tag}"
63-
Popen(cmd.split(" ")).communicate()
64-
65-
for arch in ARCHS:
66-
arch_tag = "" if arch == "" else f"-{arch}"
67-
Popen(f"docker rmi {cls.image_name}{arch_tag}".split(" ")).communicate()
51+
Popen(f"docker rmi {cls.image_name}".split(" ")).communicate()
6852

69-
def tagged_name(self, name, architecture):
70-
tag = self.get_tag(architecture)
71-
return (name + tag, "aws-lambda-rie" + tag, self.image_name + tag)
53+
def tagged_name(self, name):
54+
tag = self.get_tag()
55+
return (name + tag, "aws-lambda-rie" + tag, self.image_name)
7256

73-
def get_tag(self, architecture):
74-
return "" if architecture == "" else str(f"-{architecture}")
57+
def get_tag(self):
58+
return "" if self.ARCH == "" else str(f"-{self.ARCH}")
7559

7660
def run_command(self, cmd):
7761
Popen(cmd.split(" ")).communicate()
7862

7963
def sleep_1s(self):
8064
time.sleep(SLEEP_TIME)
8165

82-
def invoke_function(self, port):
66+
def invoke_function(self):
8367
return requests.post(
84-
f"http://localhost:{port}/2015-03-31/functions/function/invocations", json={}
68+
f"http://localhost:{self.PORT}/2015-03-31/functions/function/invocations", json={}
8569
)
8670

87-
def create_container_and_invoke_function(self, cmd, port):
88-
self.run_command(cmd)
71+
@contextmanager
72+
def create_container(self, param, image):
73+
try:
74+
platform = "x86_64" if self.ARCH == "" else self.ARCH
75+
cmd_full = f"docker run --platform linux/{platform} {param}"
76+
self.run_command(cmd_full)
8977

90-
# sleep 1s to give enough time for the endpoint to be up to curl
91-
self.sleep_1s()
78+
# sleep 1s to give enough time for the endpoint to be up to curl
79+
self.sleep_1s()
80+
yield
81+
except Exception as e:
82+
print(f"An error occurred while executing cmd: {cmd_full}. error: {e}")
83+
raise e
84+
finally:
85+
self.run_command(f"docker stop {image}")
86+
self.run_command(f"docker rm -f {image}")
9287

93-
return self.invoke_function(port)
9488

95-
@parameterized.expand([("x86_64", "8000"), ("arm64", "9000"), ("", "9050")])
96-
def test_env_var_with_equal_sign(self, arch, port):
97-
image, rie, image_name = self.tagged_name("envvarcheck", arch)
98-
99-
cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_env_var_handler"
89+
def test_env_var_with_equal_sign(self):
90+
image, rie, image_name = self.tagged_name("envvarcheck")
91+
params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_env_var_handler"
10092

101-
r = self.create_container_and_invoke_function(cmd, port)
93+
with self.create_container(params, image):
94+
r = self.invoke_function()
10295

103-
self.assertEqual(b'"4=4"', r.content)
96+
self.assertEqual(b'"4=4"', r.content)
10497

105-
@parameterized.expand([("x86_64", "8001"), ("arm64", "9001"), ("", "9051")])
106-
def test_two_invokes(self, arch, port):
107-
image, rie, image_name = self.tagged_name("twoinvokes", arch)
10898

109-
cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler"
99+
def test_two_invokes(self):
100+
image, rie, image_name = self.tagged_name("twoinvokes")
110101

111-
r = self.create_container_and_invoke_function(cmd, port)
112-
113-
self.assertEqual(b'"My lambda ran succesfully"', r.content)
102+
params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler"
114103

115-
# Make sure we can invoke the function twice
116-
r = self.invoke_function(port)
104+
with self.create_container(params, image):
105+
r = self.invoke_function()
117106

118-
self.assertEqual(b'"My lambda ran succesfully"', r.content)
107+
self.assertEqual(b'"My lambda ran succesfully"', r.content)
108+
109+
# Make sure we can invoke the function twice
110+
r = self.invoke_function()
111+
112+
self.assertEqual(b'"My lambda ran succesfully"', r.content)
113+
119114

120-
@parameterized.expand([("x86_64", "8002"), ("arm64", "9002"), ("", "9052")])
121-
def test_lambda_function_arn_exists(self, arch, port):
122-
image, rie, image_name = self.tagged_name("arnexists", arch)
115+
def test_lambda_function_arn_exists(self):
116+
image, rie, image_name = self.tagged_name("arnexists")
123117

124-
cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_lambda_arn_in_context"
118+
params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_lambda_arn_in_context"
125119

126-
r = self.create_container_and_invoke_function(cmd, port)
120+
with self.create_container(params, image):
121+
r = self.invoke_function()
127122

128-
self.assertEqual(b'"My lambda ran succesfully"', r.content)
123+
self.assertEqual(b'"My lambda ran succesfully"', r.content)
124+
129125

130-
@parameterized.expand([("x86_64", "8003"), ("arm64", "9003"), ("", "9053")])
131-
def test_lambda_function_arn_exists_with_defining_custom_name(self, arch, port):
132-
image, rie, image_name = self.tagged_name("customname", arch)
126+
def test_lambda_function_arn_exists_with_defining_custom_name(self):
127+
image, rie, image_name = self.tagged_name("customname")
133128

134-
cmd = f"docker run --name {image} --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_lambda_arn_in_context"
129+
params = f"--name {image} --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_lambda_arn_in_context"
135130

136-
r = self.create_container_and_invoke_function(cmd, port)
131+
with self.create_container(params, image):
132+
r = self.invoke_function()
137133

138-
self.assertEqual(b'"My lambda ran succesfully"', r.content)
134+
self.assertEqual(b'"My lambda ran succesfully"', r.content)
139135

140-
@parameterized.expand([("x86_64", "8004"), ("arm64", "9004"), ("", "9054")])
141-
def test_timeout_invoke(self, arch, port):
142-
image, rie, image_name = self.tagged_name("timeout", arch)
143136

144-
cmd = f"docker run --name {image} -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=1 -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.sleep_handler"
137+
def test_timeout_invoke(self):
138+
image, rie, image_name = self.tagged_name("timeout")
145139

146-
r = self.create_container_and_invoke_function(cmd, port)
140+
params = f"--name {image} -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=1 -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.sleep_handler"
141+
142+
with self.create_container(params, image):
143+
r = self.invoke_function()
147144

148-
self.assertEqual(b"Task timed out after 1.00 seconds", r.content)
145+
self.assertEqual(b"Task timed out after 1.00 seconds", r.content)
149146

150-
@parameterized.expand([("x86_64", "8005"), ("arm64", "9005"), ("", "9055")])
151-
def test_exception_returned(self, arch, port):
152-
image, rie, image_name = self.tagged_name("exception", arch)
153147

154-
cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.exception_handler"
148+
def test_exception_returned(self):
149+
image, rie, image_name = self.tagged_name("exception")
150+
151+
params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.exception_handler"
152+
153+
with self.create_container(params, image):
154+
r = self.invoke_function()
155+
156+
# Except the 3 fields assrted below, there's another field `request_id` included start from python3.12 runtime.
157+
# We should ignore asserting the field `request_id` for it is in a UUID like format and changes everytime
158+
result = r.json()
159+
self.assertEqual(result["errorMessage"], "Raising an exception")
160+
self.assertEqual(result["errorType"], "Exception")
161+
self.assertEqual(result["stackTrace"], [" File \"/var/task/main.py\", line 13, in exception_handler\n raise Exception(\"Raising an exception\")\n"])
155162

156-
r = self.create_container_and_invoke_function(cmd, port)
157-
158-
self.assertEqual(
159-
b'{"errorMessage": "Raising an exception", "errorType": "Exception", "stackTrace": [" File \\"/var/task/main.py\\", line 13, in exception_handler\\n raise Exception(\\"Raising an exception\\")\\n"]}',
160-
r.content,
161-
)
162163

163-
@parameterized.expand([("x86_64", "8006"), ("arm64", "9006"), ("", "9056")])
164-
def test_context_get_remaining_time_in_three_seconds(self, arch, port):
165-
image, rie, image_name = self.tagged_name("remaining_time_in_three_seconds", arch)
164+
def test_context_get_remaining_time_in_three_seconds(self):
165+
image, rie, image_name = self.tagged_name("remaining_time_in_three_seconds")
166166

167-
cmd = f"docker run --name {image} -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=3 -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler"
167+
params = f"--name {image} -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=3 -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler"
168168

169-
r = self.create_container_and_invoke_function(cmd, port)
169+
with self.create_container(params, image):
170+
r = self.invoke_function()
170171

171-
# Execution time is not decided, 1.0s ~ 3.0s is a good estimation
172-
self.assertLess(int(r.content), 3000)
173-
self.assertGreater(int(r.content), 1000)
172+
# Execution time is not decided, 1.0s ~ 3.0s is a good estimation
173+
self.assertLess(int(r.content), 3000)
174+
self.assertGreater(int(r.content), 1000)
174175

175-
@parameterized.expand([("x86_64", "8007"), ("arm64", "9007"), ("", "9057")])
176-
def test_context_get_remaining_time_in_ten_seconds(self, arch, port):
177-
image, rie, image_name = self.tagged_name("remaining_time_in_ten_seconds", arch)
178176

179-
cmd = f"docker run --name {image} -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=10 -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler"
177+
def test_context_get_remaining_time_in_ten_seconds(self):
178+
image, rie, image_name = self.tagged_name("remaining_time_in_ten_seconds")
180179

181-
r = self.create_container_and_invoke_function(cmd, port)
180+
params = f"--name {image} -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=10 -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler"
181+
182+
with self.create_container(params, image):
183+
r = self.invoke_function()
182184

183-
# Execution time is not decided, 8.0s ~ 10.0s is a good estimation
184-
self.assertLess(int(r.content), 10000)
185-
self.assertGreater(int(r.content), 8000)
185+
# Execution time is not decided, 8.0s ~ 10.0s is a good estimation
186+
self.assertLess(int(r.content), 10000)
187+
self.assertGreater(int(r.content), 8000)
188+
189+
190+
def test_context_get_remaining_time_in_default_deadline(self):
191+
image, rie, image_name = self.tagged_name("remaining_time_in_default_deadline")
186192

187-
@parameterized.expand([("x86_64", "8008"), ("arm64", "9008"), ("", "9058")])
188-
def test_context_get_remaining_time_in_default_deadline(self, arch, port):
189-
image, rie, image_name = self.tagged_name("remaining_time_in_default_deadline", arch)
193+
params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler"
190194

191-
cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler"
195+
with self.create_container(params, image):
196+
r = self.invoke_function()
192197

193-
r = self.create_container_and_invoke_function(cmd, port)
198+
# Executation time is not decided, 298.0s ~ 300.0s is a good estimation
199+
self.assertLess(int(r.content), 300000)
200+
self.assertGreater(int(r.content), 298000)
194201

195-
# Executation time is not decided, 298.0s ~ 300.0s is a good estimation
196-
self.assertLess(int(r.content), 300000)
197-
self.assertGreater(int(r.content), 298000)
198202

199-
@parameterized.expand([("x86_64", "8009"), ("arm64", "9009"), ("", "9059")])
200-
def test_invoke_with_pre_runtime_api_runtime(self, arch, port):
201-
image, rie, image_name = self.tagged_name("pre-runtime-api", arch)
203+
def test_invoke_with_pre_runtime_api_runtime(self):
204+
image, rie, image_name = self.tagged_name("pre-runtime-api")
202205

203-
cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler"
206+
params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler"
204207

205-
r = self.create_container_and_invoke_function(cmd, port)
208+
with self.create_container(params, image):
209+
r = self.invoke_function()
206210

207-
self.assertEqual(b'"My lambda ran succesfully"', r.content)
211+
self.assertEqual(b'"My lambda ran succesfully"', r.content)
208212

209-
@parameterized.expand([("x86_64", "8010"), ("arm64", "9010"), ("", "9060")])
210-
def test_function_name_is_overriden(self, arch, port):
211-
image, rie, image_name = self.tagged_name("assert-overwritten", arch)
212213

213-
cmd = f"docker run --name {image} -d --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_env_var_is_overwritten"
214+
def test_function_name_is_overriden(self):
215+
image, rie, image_name = self.tagged_name("assert-overwritten")
214216

215-
r = self.create_container_and_invoke_function(cmd, port)
217+
params = f"--name {image} -d --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_env_var_is_overwritten"
218+
219+
with self.create_container(params, image):
220+
r = self.invoke_function()
216221

217-
self.assertEqual(b'"My lambda ran succesfully"', r.content)
222+
self.assertEqual(b'"My lambda ran succesfully"', r.content)
223+
218224

219-
@parameterized.expand([("x86_64", "8011"), ("arm64", "9011"), ("", "9061")])
220-
def test_port_override(self, arch, port):
221-
image, rie, image_name = self.tagged_name("port_override", arch)
225+
def test_port_override(self):
226+
image, rie, image_name = self.tagged_name("port_override")
222227

223228
# Use port 8081 inside the container instead of 8080
224-
cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8081 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler --runtime-interface-emulator-address 0.0.0.0:8081"
229+
params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8081 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler --runtime-interface-emulator-address 0.0.0.0:8081"
225230

226-
r = self.create_container_and_invoke_function(cmd, port)
231+
with self.create_container(params, image):
232+
r = self.invoke_function()
227233

228-
self.assertEqual(b'"My lambda ran succesfully"', r.content)
234+
self.assertEqual(b'"My lambda ran succesfully"', r.content)
235+
229236

230237

231238
if __name__ == "__main__":

‎test/integration/testdata/Dockerfile-allinone

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM public.ecr.aws/lambda/python:3.8
1+
ARG IMAGE_ARCH
2+
FROM public.ecr.aws/lambda/python:3.12-$IMAGE_ARCH
23

34
WORKDIR /var/task
45
COPY ./ ./

0 commit comments

Comments
 (0)
Please sign in to comment.