"""mumble — TCP health parity port (Phase 2 P2).

SOURCE: recipe-info/mumble/tests/health_check.py — "Confirms the mumble server is listening on
port 64738 via TCP connection test." The original SSHes to the server and probes localhost:64738;
here the cc-ci run executes on the cc-ci host (cc-ci-run) and the recipe is deployed with
compose.host-ports.yml, so 64738 is published on the host — we probe 127.0.0.1:64738 directly.
"""

from __future__ import annotations

import socket
import time


def test_mumble_listening_on_64738(live_app):
    """The mumble voice server accepts a TCP connection on 64738 (host-published)."""
    deadline = time.time() + 60
    last_err = None
    while time.time() < deadline:
        try:
            with socket.create_connection(("127.0.0.1", 64738), timeout=10):
                return  # connected — server is listening
        except OSError as e:  # noqa: PERF203
            last_err = e
            time.sleep(3)
    raise AssertionError(f"mumble not listening on 127.0.0.1:64738 — last error: {last_err}")
