Skip to content

Commit c74d3be

Browse files
committed
Adjust timeout in shutdown function's test
Signed-off-by: Petr Shumilov <p.shumilov@vkteam.ru>
1 parent ef8c2fd commit c74d3be

2 files changed

Lines changed: 41 additions & 19 deletions

File tree

tests/python/lib/engine.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ def assert_log(self, expect, message="Can't wait expected log", timeout=60):
233233
expected_str = json.dumps(obj=expected_msgs, indent=2)
234234
raise RuntimeError("{}; Missed messages: {}".format(message, expected_str))
235235

236+
def assert_no_log(self, unexpect, message="Got unexpected log", timeout=60):
237+
success = False
238+
try:
239+
self.assert_log(expect=unexpect, timeout=timeout)
240+
success = True
241+
except Exception as e:
242+
if success:
243+
raise RuntimeError("{}; Unexpected message: {}".format(message, unexpect))
244+
245+
236246
def get_stats(self, prefix="", timeout=60):
237247
"""
238248
Получить последнюю стату движка

tests/python/tests/shutdown_functions/test_shutdown_functions_timeouts.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)