Skip to content

Commit 812c164

Browse files
committed
tests(internal): add direct unit tests for retry_extended
why: Module had no direct tests, only indirect coverage via waiter mocking what: - Test immediate success (returns True on first call) - Test success after multiple retries - Test timeout with raises=True (raises WaitTimeout) - Test timeout with raises=False (returns False, WaitTimeout)
1 parent e29d4b6 commit 812c164

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""Tests for retry_until_extended function."""
2+
3+
from __future__ import annotations
4+
5+
import pytest
6+
7+
from libtmux._internal.retry_extended import retry_until_extended
8+
from libtmux.exc import WaitTimeout
9+
10+
11+
def test_retry_success_immediate() -> None:
12+
"""Test function returns True immediately on first call."""
13+
call_count = 0
14+
15+
def always_true() -> bool:
16+
nonlocal call_count
17+
call_count += 1
18+
return True
19+
20+
success, exception = retry_until_extended(always_true, seconds=1.0)
21+
22+
assert success is True
23+
assert exception is None
24+
assert call_count == 1
25+
26+
27+
def test_retry_success_after_attempts() -> None:
28+
"""Test function succeeds after a few retries."""
29+
call_count = 0
30+
31+
def succeeds_on_third() -> bool:
32+
nonlocal call_count
33+
call_count += 1
34+
return call_count >= 3
35+
36+
success, exception = retry_until_extended(
37+
succeeds_on_third,
38+
seconds=2.0,
39+
interval=0.01,
40+
)
41+
42+
assert success is True
43+
assert exception is None
44+
assert call_count == 3
45+
46+
47+
def test_retry_timeout_raises() -> None:
48+
"""Test timeout raises WaitTimeout when raises=True."""
49+
with pytest.raises(WaitTimeout, match="Timed out after"):
50+
retry_until_extended(
51+
lambda: False,
52+
seconds=0.05,
53+
interval=0.01,
54+
raises=True,
55+
)
56+
57+
58+
def test_retry_timeout_no_raise() -> None:
59+
"""Test timeout returns (False, WaitTimeout) when raises=False."""
60+
success, exception = retry_until_extended(
61+
lambda: False,
62+
seconds=0.05,
63+
interval=0.01,
64+
raises=False,
65+
)
66+
67+
assert success is False
68+
assert isinstance(exception, WaitTimeout)
69+
assert "Timed out after" in str(exception)

0 commit comments

Comments
 (0)