|
25 | 25 | from aiohttp.test_utils import TestServer |
26 | 26 |
|
27 | 27 | from livekit.api import CreateRoomRequest, Room, ServerError |
| 28 | +from livekit.api._failover import FAILOVER_MAX_ATTEMPTS, failover_attempts |
28 | 29 | from livekit.api.twirp_client import TwirpClient |
29 | 30 |
|
30 | 31 | Handler = Callable[[int, web.Request], "web.StreamResponse | None"] |
@@ -87,3 +88,22 @@ def behave(attempt: int, request: web.Request): |
87 | 88 | asyncio.run(_call_single_host(behave, attempts)) |
88 | 89 | assert exc.value.status == 502 |
89 | 90 | assert len(attempts) == 1 |
| 91 | + |
| 92 | + |
| 93 | +@pytest.mark.parametrize( |
| 94 | + "host, expected", |
| 95 | + [ |
| 96 | + ("myproject.livekit.cloud", FAILOVER_MAX_ATTEMPTS), |
| 97 | + ("myproject.region.livekit.cloud", FAILOVER_MAX_ATTEMPTS), |
| 98 | + ("myproject.livekit.io", 1), |
| 99 | + # The LiveKit Cloud API hosts fail over too (same-host retry). |
| 100 | + ("cloud-api.livekit.io", FAILOVER_MAX_ATTEMPTS), |
| 101 | + ("cloud-api.staging.livekit.io", FAILOVER_MAX_ATTEMPTS), |
| 102 | + ("cloud-api.example.com", 1), |
| 103 | + ("example.com", 1), |
| 104 | + ("127.0.0.1", 1), |
| 105 | + ("notlivekit.cloud", 1), |
| 106 | + ], |
| 107 | +) |
| 108 | +def test_failover_attempts(host: str, expected: int): |
| 109 | + assert failover_attempts(True, host) == expected |
0 commit comments