@@ -109,6 +109,21 @@ def test_wait_next_invocation(self, mock_runtime_client):
109
109
110
110
headers = {"Lambda-Runtime-Function-Error-Type" : error_result ["errorType" ]}
111
111
112
+ restore_error_result = {
113
+ "errorMessage" : "Dummy Restore error" ,
114
+ "errorType" : "Runtime.DummyRestoreError" ,
115
+ "requestId" : "" ,
116
+ "stackTrace" : [],
117
+ }
118
+
119
+ restore_error_header = {
120
+ "Lambda-Runtime-Function-Error-Type" : "Runtime.AfterRestoreError"
121
+ }
122
+
123
+ before_snapshot_error_header = {
124
+ "Lambda-Runtime-Function-Error-Type" : "Runtime.BeforeSnapshotError"
125
+ }
126
+
112
127
@patch ("http.client.HTTPConnection" , autospec = http .client .HTTPConnection )
113
128
def test_post_init_error (self , MockHTTPConnection ):
114
129
mock_conn = MockHTTPConnection .return_value
@@ -225,6 +240,64 @@ def test_post_invocation_error_with_too_large_xray_cause(self, mock_runtime_clie
225
240
invoke_id , error_data , ""
226
241
)
227
242
243
+ @patch ("http.client.HTTPConnection" , autospec = http .client .HTTPConnection )
244
+ def test_restore_next (self , MockHTTPConnection ):
245
+ mock_conn = MockHTTPConnection .return_value
246
+ mock_response = MagicMock (autospec = http .client .HTTPResponse )
247
+ mock_conn .getresponse .return_value = mock_response
248
+ mock_response .read .return_value = b""
249
+ mock_response .code = http .HTTPStatus .OK
250
+
251
+ runtime_client = LambdaRuntimeClient ("localhost:1234" )
252
+ runtime_client .restore_next ()
253
+
254
+ MockHTTPConnection .assert_called_with ("localhost:1234" )
255
+ mock_conn .request .assert_called_once_with (
256
+ "GET" ,
257
+ "/2018-06-01/runtime/restore/next" ,
258
+ )
259
+ mock_response .read .assert_called_once ()
260
+
261
+ @patch ("http.client.HTTPConnection" , autospec = http .client .HTTPConnection )
262
+ def test_restore_error (self , MockHTTPConnection ):
263
+ mock_conn = MockHTTPConnection .return_value
264
+ mock_response = MagicMock (autospec = http .client .HTTPResponse )
265
+ mock_conn .getresponse .return_value = mock_response
266
+ mock_response .read .return_value = b""
267
+ mock_response .code = http .HTTPStatus .ACCEPTED
268
+
269
+ runtime_client = LambdaRuntimeClient ("localhost:1234" )
270
+ runtime_client .report_restore_error (self .restore_error_result )
271
+
272
+ MockHTTPConnection .assert_called_with ("localhost:1234" )
273
+ mock_conn .request .assert_called_once_with (
274
+ "POST" ,
275
+ "/2018-06-01/runtime/restore/error" ,
276
+ to_json (self .restore_error_result ),
277
+ headers = self .restore_error_header ,
278
+ )
279
+ mock_response .read .assert_called_once ()
280
+
281
+ @patch ("http.client.HTTPConnection" , autospec = http .client .HTTPConnection )
282
+ def test_init_before_snapshot_error (self , MockHTTPConnection ):
283
+ mock_conn = MockHTTPConnection .return_value
284
+ mock_response = MagicMock (autospec = http .client .HTTPResponse )
285
+ mock_conn .getresponse .return_value = mock_response
286
+ mock_response .read .return_value = b""
287
+ mock_response .code = http .HTTPStatus .ACCEPTED
288
+
289
+ runtime_client = LambdaRuntimeClient ("localhost:1234" )
290
+ runtime_client .post_init_error (self .error_result , "Runtime.BeforeSnapshotError" )
291
+
292
+ MockHTTPConnection .assert_called_with ("localhost:1234" )
293
+ mock_conn .request .assert_called_once_with (
294
+ "POST" ,
295
+ "/2018-06-01/runtime/init/error" ,
296
+ to_json (self .error_result ),
297
+ headers = self .before_snapshot_error_header ,
298
+ )
299
+ mock_response .read .assert_called_once ()
300
+
228
301
def test_connection_refused (self ):
229
302
with self .assertRaises (ConnectionRefusedError ):
230
303
runtime_client = LambdaRuntimeClient ("127.0.0.1:1" )
0 commit comments