From 5277067341bb480fc76320dbd951551b420a6ab0 Mon Sep 17 00:00:00 2001
From: Petr Shumilov
Date: Wed, 1 Apr 2026 16:11:38 +0300
Subject: [PATCH] Adjust timeout in shutdown function's test
Signed-off-by: Petr Shumilov
---
tests/python/lib/engine.py | 9 ++++
.../test_shutdown_functions_timeouts.py | 50 ++++++++++++-------
2 files changed, 40 insertions(+), 19 deletions(-)
diff --git a/tests/python/lib/engine.py b/tests/python/lib/engine.py
index 34643d2ab2..b9e7b9bcf4 100644
--- a/tests/python/lib/engine.py
+++ b/tests/python/lib/engine.py
@@ -233,6 +233,15 @@ 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):
+ try:
+ self.assert_log(expect=unexpect, timeout=timeout)
+ except Exception:
+ pass
+ else:
+ raise RuntimeError("{}; Unexpected message: {}".format(message, unexpect))
+
+
def get_stats(self, prefix="", timeout=60):
"""
Получить последнюю стату движка
diff --git a/tests/python/tests/shutdown_functions/test_shutdown_functions_timeouts.py b/tests/python/tests/shutdown_functions/test_shutdown_functions_timeouts.py
index 8cf940c2f5..0af90132f7 100644
--- a/tests/python/tests/shutdown_functions/test_shutdown_functions_timeouts.py
+++ b/tests/python/tests/shutdown_functions/test_shutdown_functions_timeouts.py
@@ -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, may 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
@@ -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
@@ -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)