Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/python/lib/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ def assert_log(self, expect, message="Can't wait expected log", timeout=60):
expected_str = json.dumps(obj=expected_msgs, indent=2)
raise RuntimeError("{}; Missed messages: {}".format(message, expected_str))

def assert_no_log(self, unexpect, message="Got unexpected log", timeout=60):
success = False
try:
self.assert_log(expect=unexpect, timeout=timeout)
success = True
except Exception as e:
if success:
raise RuntimeError("{}; Unexpected message: {}".format(message, unexpect))
Comment on lines +237 to +243
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If self.assert_log doesn't raise an exception then nothing happens

Suggested change
success = False
try:
self.assert_log(expect=unexpect, timeout=timeout)
success = True
except Exception as e:
if success:
raise RuntimeError("{}; Unexpected message: {}".format(message, unexpect))
try:
self.assert_log(expect=unexpect, timeout=timeout)
except Exception as e:
pass
else:
raise RuntimeError("{}; Unexpected message: {}".format(message, unexpect))



def get_stats(self, prefix="", timeout=60):
"""
Получить последнюю стату движка
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ def test_soft_timeout_checking_in_resumable(self):
json=[
{"op": "register_shutdown_function", "msg": "shutdown_simple"},
{"op": "register_shutdown_function", "msg": "shutdown_send_rpc"},
{"op": "sleep", "duration": 1.5},
{"op": "resumable_long_work", "duration": 0.2},
{"op": "critical_error"},
{"op": "long_work", "duration": 1.3},
{"op": "resumable_long_work", "duration": 0.2}, # must not to be started, should invokes shutdown functions
{"op": "critical_error"}, # unfortunately, produces a lot of flaky
])
self.assertEqual(resp.text, "ERROR")
self.assertEqual(resp.status_code, 500)
self.web_server.assert_log(["execute simple shutdown", "try send rpc from shutdown"], timeout=5)
self.web_server.assert_no_log(unexpect=["finish resumable_long_work"], timeout=10) # consider it is unreachable
self.web_server.assert_log(["execute simple shutdown", "try send rpc from shutdown"], timeout=10)

def test_timeout_reset_at_shutdown_function(self):
# test that the timeout timer resets, giving the shutdown functions a chance to complete
Expand All @@ -53,21 +54,6 @@ def test_timeout_reset_at_shutdown_function(self):
self.assertEqual(resp.status_code, 200)
self.web_server.assert_log(["shutdown function managed to finish"], timeout=5)

def test_timeout_shutdown_exit(self):
# test that if we're doing an exit(0) in shutdown handler *after* the timeout
# that request will still end up in error state with 500 status code
resp = self.web_server.http_post(
json=[
{"op": "register_shutdown_function", "msg": "shutdown_with_exit"},
{"op": "long_work", "duration": 1.5}
])
self.assertEqual(resp.text, "ERROR")
self.assertEqual(resp.status_code, 500)
self.web_server.assert_log([
"Critical error during script execution: timeout exit",
"running shutdown handler 1"
], timeout=5)

def test_timeout_after_timeout_at_shutdown_function(self):
# test that we do set up a second timeout for the shutdown functions
# that were executed *after* the (first) timeout
Expand Down Expand Up @@ -151,3 +137,29 @@ def test_timeout_after_timeout_at_shutdown_function(self):
# self.assertEqual(resp.status_code, 500)
# self.web_server.assert_log(["Critical error during script execution: timeout",
# "shutdown function managed to finish"], timeout=5)


@pytest.mark.k2_skip_suite
class TestShutdownFunctionsWithLongHardTimeout(WebServerAutoTestCase):
@classmethod
def extra_class_setup(cls):
cls.web_server.update_options({
"--time-limit": 1,
"--hard-time-limit": 5,
"--verbosity-resumable=2": True,
})

def test_timeout_shutdown_exit(self):
# test that if we're doing an exit(0) in shutdown handler *after* the timeout
# that request will still end up in error state with 500 status code
resp = self.web_server.http_post(
json=[
{"op": "register_shutdown_function", "msg": "shutdown_with_exit"},
{"op": "long_work", "duration": 1.5}
])
self.assertEqual(resp.text, "ERROR")
self.assertEqual(resp.status_code, 500)
self.web_server.assert_log([
"Critical error during script execution: timeout exit",
"running shutdown handler 1"
], timeout=5)
Loading