@@ -48,6 +48,9 @@ def tearDownClass(cls):
48
48
"customname" ,
49
49
"timeout" ,
50
50
"exception" ,
51
+ "remaining_time_in_three_seconds" ,
52
+ "remaining_time_in_ten_seconds" ,
53
+ "remaining_time_in_default_deadline" ,
51
54
"pre-runtime-api" ,
52
55
"assert-overwritten" ,
53
56
]
@@ -65,11 +68,11 @@ def tearDownClass(cls):
65
68
def tagged_name (self , name , architecture ):
66
69
tag = self .get_tag (architecture )
67
70
return (name + tag , "aws-lambda-rie" + tag , self .image_name + tag )
68
-
71
+
69
72
def get_tag (self , architecture ):
70
73
return "" if architecture == "" else str (f"-{ architecture } " )
71
74
72
- @parameterized .expand ([("x86_64" , "8000" ), ("arm64" , "9001 " ), ("" , "9003 " )])
75
+ @parameterized .expand ([("x86_64" , "8000" ), ("arm64" , "9000 " ), ("" , "9050 " )])
73
76
def test_env_var_with_equal_sign (self , arch , port ):
74
77
image , rie , image_name = self .tagged_name ("envvarcheck" , arch )
75
78
@@ -84,7 +87,7 @@ def test_env_var_with_equal_sign(self, arch, port):
84
87
)
85
88
self .assertEqual (b'"4=4"' , r .content )
86
89
87
- @parameterized .expand ([("x86_64" , "8001" ), ("arm64" , "9002 " ), ("" , "9005 " )])
90
+ @parameterized .expand ([("x86_64" , "8001" ), ("arm64" , "9001 " ), ("" , "9051 " )])
88
91
def test_two_invokes (self , arch , port ):
89
92
image , rie , image_name = self .tagged_name ("twoinvokes" , arch )
90
93
@@ -106,10 +109,10 @@ def test_two_invokes(self, arch, port):
106
109
)
107
110
self .assertEqual (b'"My lambda ran succesfully"' , r .content )
108
111
109
- @parameterized .expand ([("x86_64" , "8002" ), ("arm64" , "9004 " ), ("" , "9007 " )])
112
+ @parameterized .expand ([("x86_64" , "8002" ), ("arm64" , "9002 " ), ("" , "9052 " )])
110
113
def test_lambda_function_arn_exists (self , arch , port ):
111
114
image , rie , image_name = self .tagged_name ("arnexists" , arch )
112
-
115
+
113
116
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"
114
117
115
118
Popen (cmd .split (" " )).communicate ()
@@ -122,10 +125,10 @@ def test_lambda_function_arn_exists(self, arch, port):
122
125
)
123
126
self .assertEqual (b'"My lambda ran succesfully"' , r .content )
124
127
125
- @parameterized .expand ([("x86_64" , "8003" ), ("arm64" , "9006 " ), ("" , "9009 " )])
128
+ @parameterized .expand ([("x86_64" , "8003" ), ("arm64" , "9003 " ), ("" , "9053 " )])
126
129
def test_lambda_function_arn_exists_with_defining_custom_name (self , arch , port ):
127
130
image , rie , image_name = self .tagged_name ("customname" , arch )
128
-
131
+
129
132
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"
130
133
Popen (cmd .split (" " )).communicate ()
131
134
@@ -137,10 +140,10 @@ def test_lambda_function_arn_exists_with_defining_custom_name(self, arch, port):
137
140
)
138
141
self .assertEqual (b'"My lambda ran succesfully"' , r .content )
139
142
140
- @parameterized .expand ([("x86_64" , "8004" ), ("arm64" , "9008 " ), ("" , "9011 " )])
143
+ @parameterized .expand ([("x86_64" , "8004" ), ("arm64" , "9004 " ), ("" , "9054 " )])
141
144
def test_timeout_invoke (self , arch , port ):
142
145
image , rie , image_name = self .tagged_name ("timeout" , arch )
143
-
146
+
144
147
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"
145
148
146
149
Popen (cmd .split (" " )).communicate ()
@@ -153,10 +156,10 @@ def test_timeout_invoke(self, arch, port):
153
156
)
154
157
self .assertEqual (b"Task timed out after 1.00 seconds" , r .content )
155
158
156
- @parameterized .expand ([("x86_64" , "8005" ), ("arm64" , "9010 " ), ("" , "9013 " )])
159
+ @parameterized .expand ([("x86_64" , "8005" ), ("arm64" , "9005 " ), ("" , "9055 " )])
157
160
def test_exception_returned (self , arch , port ):
158
161
image , rie , image_name = self .tagged_name ("exception" , arch )
159
-
162
+
160
163
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"
161
164
162
165
Popen (cmd .split (" " )).communicate ()
@@ -172,10 +175,67 @@ def test_exception_returned(self, arch, port):
172
175
r .content ,
173
176
)
174
177
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" )])
176
236
def test_invoke_with_pre_runtime_api_runtime (self , arch , port ):
177
237
image , rie , image_name = self .tagged_name ("pre-runtime-api" , arch )
178
-
238
+
179
239
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"
180
240
181
241
Popen (cmd .split (" " )).communicate ()
@@ -188,10 +248,10 @@ def test_invoke_with_pre_runtime_api_runtime(self, arch, port):
188
248
)
189
249
self .assertEqual (b'"My lambda ran succesfully"' , r .content )
190
250
191
- @parameterized .expand ([("x86_64" , "8007 " ), ("arm64" , "9014 " ), ("" , "9016 " )])
251
+ @parameterized .expand ([("x86_64" , "8010 " ), ("arm64" , "9010 " ), ("" , "9060 " )])
192
252
def test_function_name_is_overriden (self , arch , port ):
193
253
image , rie , image_name = self .tagged_name ("assert-overwritten" , arch )
194
-
254
+
195
255
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"
196
256
197
257
Popen (cmd .split (" " )).communicate ()
@@ -206,4 +266,4 @@ def test_function_name_is_overriden(self, arch, port):
206
266
207
267
208
268
if __name__ == "__main__" :
209
- main ()
269
+ main ()
0 commit comments