fix: installer starts the service reliably (retry + verify + installer.log), fails loudly; 1.1.6
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -35,7 +35,7 @@ def world(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(common, "write_arp_uninstall", lambda d: None)
|
||||
monkeypatch.setattr(common, "service_running", lambda: False)
|
||||
monkeypatch.setattr(common, "service_installed", lambda: True)
|
||||
monkeypatch.setattr(common, "start_service", lambda: calls.append(("start",)))
|
||||
monkeypatch.setattr(common, "start_and_verify", lambda *a, **k: calls.append(("start",)) or (True, "RUNNING"))
|
||||
monkeypatch.setattr(common, "ensure_service_stopped", lambda timeout=45.0: calls.append(("stop",)))
|
||||
monkeypatch.setattr(common, "wait_service_state", lambda wanted, timeout=45: True)
|
||||
monkeypatch.setattr(common, "wait_for_heartbeat", lambda token, hub, timeout=120: calls.append(("heartbeat_wait",)) or True)
|
||||
@@ -116,3 +116,44 @@ def test_no_write_flags_anywhere_in_zero_touch_installer():
|
||||
for name in ("setup_main.py", "firebird_discovery.py"):
|
||||
text = (ROOT / "installer" / name).read_text(encoding="utf-8")
|
||||
assert "FIREBIRD_WRITES=1" not in text and "AUTO_APPLY" not in text and "UPDATE " not in text.upper().replace("UPDATE_", "")
|
||||
|
||||
|
||||
def test_start_and_verify_retries_after_a_failed_first_start_and_logs_the_cause(monkeypatch, tmp_path):
|
||||
"""First start after fresh files typically dies with 1053 (SCM 30 s limit); the retry must succeed and installer.log must say why."""
|
||||
monkeypatch.setenv("GTI_LOG_DIR", str(tmp_path))
|
||||
monkeypatch.setenv("GTI_INSTALL_DIR", str(tmp_path / "inst"))
|
||||
state = {"n": 0, "starts": 0}
|
||||
|
||||
def fake_state():
|
||||
return "RUNNING" if state["starts"] >= 2 else "STOPPED"
|
||||
|
||||
def fake_sc(args):
|
||||
if args[0] == "start":
|
||||
state["starts"] += 1
|
||||
import subprocess
|
||||
return subprocess.CompletedProcess(args, 0, "", "")
|
||||
|
||||
class Q:
|
||||
stdout = "WIN32_EXIT_CODE : 1053"
|
||||
|
||||
monkeypatch.setattr(common, "service_state", fake_state)
|
||||
monkeypatch.setattr(common, "_sc", fake_sc)
|
||||
monkeypatch.setattr(common, "service_process_alive", lambda: True)
|
||||
monkeypatch.setattr(common.subprocess, "run", lambda *a, **k: Q())
|
||||
monkeypatch.setattr(common.time, "sleep", lambda s: None)
|
||||
ok, detail = common.start_and_verify(attempts=3, per_attempt=0.01)
|
||||
assert ok and detail == "RUNNING" and state["starts"] == 2
|
||||
log = (tmp_path / "installer.log").read_text(encoding="utf-8")
|
||||
assert "attempt 1" in log and "1053" in log and "host process alive" in log
|
||||
|
||||
|
||||
def test_start_and_verify_reports_failure_after_all_attempts(monkeypatch, tmp_path):
|
||||
monkeypatch.setenv("GTI_LOG_DIR", str(tmp_path))
|
||||
monkeypatch.setenv("GTI_INSTALL_DIR", str(tmp_path / "inst"))
|
||||
monkeypatch.setattr(common, "service_state", lambda: "STOPPED")
|
||||
monkeypatch.setattr(common, "_sc", lambda a: None)
|
||||
monkeypatch.setattr(common.subprocess, "run", lambda *a, **k: type("Q", (), {"stdout": "WIN32_EXIT_CODE : 1053"})())
|
||||
monkeypatch.setattr(common.time, "sleep", lambda s: None)
|
||||
ok, detail = common.start_and_verify(attempts=2, per_attempt=0.01)
|
||||
assert not ok and "1053" in detail
|
||||
assert "NÃO iniciou" in setup_main.final_message({"service_running": False, "service_detail": detail, "install_dir": "x"})
|
||||
|
||||
Reference in New Issue
Block a user