@@ -33,13 +33,14 @@ def test_soft_timeout_checking_in_resumable(self):
3333 json = [
3434 {"op" : "register_shutdown_function" , "msg" : "shutdown_simple" },
3535 {"op" : "register_shutdown_function" , "msg" : "shutdown_send_rpc" },
36- {"op" : "sleep " , "duration" : 1.5 },
37- {"op" : "resumable_long_work" , "duration" : 0.2 },
38- {"op" : "critical_error" },
36+ {"op" : "long_work " , "duration" : 1.3 },
37+ {"op" : "resumable_long_work" , "duration" : 0.2 }, # must not to be started, should invokes shutdown functions
38+ {"op" : "critical_error" }, # unfortunately, produces a lot of flaky
3939 ])
4040 self .assertEqual (resp .text , "ERROR" )
4141 self .assertEqual (resp .status_code , 500 )
42- self .web_server .assert_log (["execute simple shutdown" , "try send rpc from shutdown" ], timeout = 5 )
42+ self .web_server .assert_no_log (unexpect = ["finish resumable_long_work" ], timeout = 10 ) # consider it is unreachable
43+ self .web_server .assert_log (["execute simple shutdown" , "try send rpc from shutdown" ], timeout = 10 )
4344
4445 def test_timeout_reset_at_shutdown_function (self ):
4546 # test that the timeout timer resets, giving the shutdown functions a chance to complete
@@ -53,21 +54,6 @@ def test_timeout_reset_at_shutdown_function(self):
5354 self .assertEqual (resp .status_code , 200 )
5455 self .web_server .assert_log (["shutdown function managed to finish" ], timeout = 5 )
5556
56- def test_timeout_shutdown_exit (self ):
57- # test that if we're doing an exit(0) in shutdown handler *after* the timeout
58- # that request will still end up in error state with 500 status code
59- resp = self .web_server .http_post (
60- json = [
61- {"op" : "register_shutdown_function" , "msg" : "shutdown_with_exit" },
62- {"op" : "long_work" , "duration" : 1.5 }
63- ])
64- self .assertEqual (resp .text , "ERROR" )
65- self .assertEqual (resp .status_code , 500 )
66- self .web_server .assert_log ([
67- "Critical error during script execution: timeout exit" ,
68- "running shutdown handler 1"
69- ], timeout = 5 )
70-
7157 def test_timeout_after_timeout_at_shutdown_function (self ):
7258 # test that we do set up a second timeout for the shutdown functions
7359 # that were executed *after* the (first) timeout
@@ -151,3 +137,29 @@ def test_timeout_after_timeout_at_shutdown_function(self):
151137 # self.assertEqual(resp.status_code, 500)
152138 # self.web_server.assert_log(["Critical error during script execution: timeout",
153139 # "shutdown function managed to finish"], timeout=5)
140+
141+
142+ @pytest .mark .k2_skip_suite
143+ class TestShutdownFunctionsWithLongHardTimeout (WebServerAutoTestCase ):
144+ @classmethod
145+ def extra_class_setup (cls ):
146+ cls .web_server .update_options ({
147+ "--time-limit" : 1 ,
148+ "--hard-time-limit" : 5 ,
149+ "--verbosity-resumable=2" : True ,
150+ })
151+
152+ def test_timeout_shutdown_exit (self ):
153+ # test that if we're doing an exit(0) in shutdown handler *after* the timeout
154+ # that request will still end up in error state with 500 status code
155+ resp = self .web_server .http_post (
156+ json = [
157+ {"op" : "register_shutdown_function" , "msg" : "shutdown_with_exit" },
158+ {"op" : "long_work" , "duration" : 1.5 }
159+ ])
160+ self .assertEqual (resp .text , "ERROR" )
161+ self .assertEqual (resp .status_code , 500 )
162+ self .web_server .assert_log ([
163+ "Critical error during script execution: timeout exit" ,
164+ "running shutdown handler 1"
165+ ], timeout = 5 )
0 commit comments