@@ -48,6 +48,9 @@ def tearDownClass(cls):
4848 "customname" ,
4949 "timeout" ,
5050 "exception" ,
51+ "remaining_time_in_three_seconds" ,
52+ "remaining_time_in_ten_seconds" ,
53+ "remaining_time_in_default_deadline" ,
5154 "pre-runtime-api" ,
5255 "assert-overwritten" ,
5356 ]
@@ -65,11 +68,11 @@ def tearDownClass(cls):
6568 def tagged_name (self , name , architecture ):
6669 tag = self .get_tag (architecture )
6770 return (name + tag , "aws-lambda-rie" + tag , self .image_name + tag )
68-
71+
6972 def get_tag (self , architecture ):
7073 return "" if architecture == "" else str (f"-{ architecture } " )
7174
72- @parameterized .expand ([("x86_64" , "8000" ), ("arm64" , "9001 " ), ("" , "9003 " )])
75+ @parameterized .expand ([("x86_64" , "8000" ), ("arm64" , "9000 " ), ("" , "9050 " )])
7376 def test_env_var_with_equal_sign (self , arch , port ):
7477 image , rie , image_name = self .tagged_name ("envvarcheck" , arch )
7578
@@ -84,7 +87,7 @@ def test_env_var_with_equal_sign(self, arch, port):
8487 )
8588 self .assertEqual (b'"4=4"' , r .content )
8689
87- @parameterized .expand ([("x86_64" , "8001" ), ("arm64" , "9002 " ), ("" , "9005 " )])
90+ @parameterized .expand ([("x86_64" , "8001" ), ("arm64" , "9001 " ), ("" , "9051 " )])
8891 def test_two_invokes (self , arch , port ):
8992 image , rie , image_name = self .tagged_name ("twoinvokes" , arch )
9093
@@ -106,10 +109,10 @@ def test_two_invokes(self, arch, port):
106109 )
107110 self .assertEqual (b'"My lambda ran succesfully"' , r .content )
108111
109- @parameterized .expand ([("x86_64" , "8002" ), ("arm64" , "9004 " ), ("" , "9007 " )])
112+ @parameterized .expand ([("x86_64" , "8002" ), ("arm64" , "9002 " ), ("" , "9052 " )])
110113 def test_lambda_function_arn_exists (self , arch , port ):
111114 image , rie , image_name = self .tagged_name ("arnexists" , arch )
112-
115+
113116 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"
114117
115118 Popen (cmd .split (" " )).communicate ()
@@ -122,10 +125,10 @@ def test_lambda_function_arn_exists(self, arch, port):
122125 )
123126 self .assertEqual (b'"My lambda ran succesfully"' , r .content )
124127
125- @parameterized .expand ([("x86_64" , "8003" ), ("arm64" , "9006 " ), ("" , "9009 " )])
128+ @parameterized .expand ([("x86_64" , "8003" ), ("arm64" , "9003 " ), ("" , "9053 " )])
126129 def test_lambda_function_arn_exists_with_defining_custom_name (self , arch , port ):
127130 image , rie , image_name = self .tagged_name ("customname" , arch )
128-
131+
129132 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"
130133 Popen (cmd .split (" " )).communicate ()
131134
@@ -137,10 +140,10 @@ def test_lambda_function_arn_exists_with_defining_custom_name(self, arch, port):
137140 )
138141 self .assertEqual (b'"My lambda ran succesfully"' , r .content )
139142
140- @parameterized .expand ([("x86_64" , "8004" ), ("arm64" , "9008 " ), ("" , "9011 " )])
143+ @parameterized .expand ([("x86_64" , "8004" ), ("arm64" , "9004 " ), ("" , "9054 " )])
141144 def test_timeout_invoke (self , arch , port ):
142145 image , rie , image_name = self .tagged_name ("timeout" , arch )
143-
146+
144147 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"
145148
146149 Popen (cmd .split (" " )).communicate ()
@@ -153,10 +156,10 @@ def test_timeout_invoke(self, arch, port):
153156 )
154157 self .assertEqual (b"Task timed out after 1.00 seconds" , r .content )
155158
156- @parameterized .expand ([("x86_64" , "8005" ), ("arm64" , "9010 " ), ("" , "9013 " )])
159+ @parameterized .expand ([("x86_64" , "8005" ), ("arm64" , "9005 " ), ("" , "9055 " )])
157160 def test_exception_returned (self , arch , port ):
158161 image , rie , image_name = self .tagged_name ("exception" , arch )
159-
162+
160163 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"
161164
162165 Popen (cmd .split (" " )).communicate ()
@@ -172,10 +175,67 @@ def test_exception_returned(self, arch, port):
172175 r .content ,
173176 )
174177
175- @parameterized .expand ([("x86_64" , "8006" ), ("arm64" , "9012" ), ("" , "9015" )])
178+ @parameterized .expand ([("x86_64" , "8006" ), ("arm64" , "9006" ), ("" , "9056" )])
179+ def test_context_get_remaining_time_in_three_seconds (self , arch , port ):
180+ image , rie , image_name = self .tagged_name ("remaining_time_in_three_seconds" , arch )
181+
182+ 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"
183+
184+ Popen (cmd .split (' ' )).communicate ()
185+
186+ # sleep 1s to give enough time for the endpoint to be up to curl
187+ time .sleep (SLEEP_TIME )
188+
189+ r = requests .post (
190+ f"http://localhost:{ port } /2015-03-31/functions/function/invocations" , json = {}
191+ )
192+
193+ # Execution time is not decided, 1.0s ~ 3.0s is a good estimation
194+ self .assertLess (int (r .content ), 3000 )
195+ self .assertGreater (int (r .content ), 1000 )
196+
197+ @parameterized .expand ([("x86_64" , "8007" ), ("arm64" , "9007" ), ("" , "9057" )])
198+ def test_context_get_remaining_time_in_ten_seconds (self , arch , port ):
199+ image , rie , image_name = self .tagged_name ("remaining_time_in_ten_seconds" , arch )
200+
201+ 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"
202+
203+ Popen (cmd .split (' ' )).communicate ()
204+
205+ # sleep 1s to give enough time for the endpoint to be up to curl
206+ time .sleep (SLEEP_TIME )
207+
208+ r = requests .post (
209+ f"http://localhost:{ port } /2015-03-31/functions/function/invocations" , json = {}
210+ )
211+
212+ # Execution time is not decided, 8.0s ~ 10.0s is a good estimation
213+ self .assertLess (int (r .content ), 10000 )
214+ self .assertGreater (int (r .content ), 8000 )
215+
216+ @parameterized .expand ([("x86_64" , "8008" ), ("arm64" , "9008" ), ("" , "9058" )])
217+ def test_context_get_remaining_time_in_default_deadline (self , arch , port ):
218+ image , rie , image_name = self .tagged_name ("remaining_time_in_default_deadline" , arch )
219+
220+ 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"
221+
222+ Popen (cmd .split (' ' )).communicate ()
223+
224+ # sleep 1s to give enough time for the endpoint to be up to curl
225+ time .sleep (SLEEP_TIME )
226+
227+ r = requests .post (
228+ f"http://localhost:{ port } /2015-03-31/functions/function/invocations" , json = {}
229+ )
230+
231+ # Executation time is not decided, 298.0s ~ 300.0s is a good estimation
232+ self .assertLess (int (r .content ), 300000 )
233+ self .assertGreater (int (r .content ), 298000 )
234+
235+ @parameterized .expand ([("x86_64" , "8009" ), ("arm64" , "9009" ), ("" , "9059" )])
176236 def test_invoke_with_pre_runtime_api_runtime (self , arch , port ):
177237 image , rie , image_name = self .tagged_name ("pre-runtime-api" , arch )
178-
238+
179239 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"
180240
181241 Popen (cmd .split (" " )).communicate ()
@@ -188,10 +248,10 @@ def test_invoke_with_pre_runtime_api_runtime(self, arch, port):
188248 )
189249 self .assertEqual (b'"My lambda ran succesfully"' , r .content )
190250
191- @parameterized .expand ([("x86_64" , "8007 " ), ("arm64" , "9014 " ), ("" , "9016 " )])
251+ @parameterized .expand ([("x86_64" , "8010 " ), ("arm64" , "9010 " ), ("" , "9060 " )])
192252 def test_function_name_is_overriden (self , arch , port ):
193253 image , rie , image_name = self .tagged_name ("assert-overwritten" , arch )
194-
254+
195255 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"
196256
197257 Popen (cmd .split (" " )).communicate ()
@@ -206,4 +266,4 @@ def test_function_name_is_overriden(self, arch, port):
206266
207267
208268if __name__ == "__main__" :
209- main ()
269+ main ()
0 commit comments