Tolerate a restarting server after the native update
The first ping after `herdr update --handoff` was sent exactly once. A server still binding its socket turned into "更新/热切换未完成" even though the update had succeeded. Retry connection errors for up to 20 seconds before giving up; a healthy server still answers immediately. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -65,6 +65,33 @@ class HandoffTests(unittest.TestCase):
|
||||
update_and_handoff("/fake/herdr", "named")
|
||||
self.assertEqual([c.args[1] for c in call.call_args_list].count("server.live_handoff"), 1)
|
||||
|
||||
def test_server_restarting_after_native_update_is_polled_not_failed(self):
|
||||
old = {"version": "0.9.0", "capabilities": {"live_handoff": True}}
|
||||
with patch("herdr_hub.restart.subprocess.check_output", return_value="status: running\nsocket: /tmp/fake.sock\n"), patch(
|
||||
"herdr_hub.restart.request",
|
||||
side_effect=[old, ConnectionRefusedError(), FileNotFoundError(), {"version": "0.9.1"}],
|
||||
) as call, patch("herdr_hub.restart.subprocess.run"), patch(
|
||||
"herdr_hub.restart.installed_version", return_value="0.9.1"
|
||||
), patch("herdr_hub.restart.time.sleep"), patch(
|
||||
"herdr_hub.restart.time.monotonic", side_effect=[0, 0.2]
|
||||
), contextlib.redirect_stdout(io.StringIO()):
|
||||
update_and_handoff("/fake/herdr", "named")
|
||||
self.assertEqual([c.args[1] for c in call.call_args_list], ["ping"] * 4)
|
||||
|
||||
def test_server_unreachable_after_update_is_reported_without_restart(self):
|
||||
old = {"version": "0.9.0", "capabilities": {"live_handoff": True}}
|
||||
with patch("herdr_hub.restart.subprocess.check_output", return_value="status: running\nsocket: /tmp/fake.sock\n"), patch(
|
||||
"herdr_hub.restart.request",
|
||||
side_effect=[old, ConnectionRefusedError(), ConnectionRefusedError()],
|
||||
) as call, patch("herdr_hub.restart.subprocess.run"), patch(
|
||||
"herdr_hub.restart.installed_version", return_value="0.9.1"
|
||||
), patch("herdr_hub.restart.time.sleep"), patch(
|
||||
"herdr_hub.restart.time.monotonic", side_effect=[0, 25]
|
||||
), contextlib.redirect_stdout(io.StringIO()):
|
||||
with self.assertRaisesRegex(RuntimeError, "无法连接 Herdr 服务器"):
|
||||
update_and_handoff("/fake/herdr", "named")
|
||||
self.assertNotIn("server.live_handoff", [c.args[1] for c in call.call_args_list])
|
||||
|
||||
def test_real_helper_updates_old_server_even_when_binary_already_latest(self):
|
||||
self._run_real_helper()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user