Skip to content

Commit 4ab3bef

Browse files
committed
refactor(tests): Replace time.sleep with wait_for_server_condition
why: Improve test reliability by using proper waiting patterns what: - Replace time.sleep in test_pytest_plugin.py with wait_for_server_condition - Add helper function to properly check if server is dead - Remove time import as it's no longer needed refs: Migrating to waiter.py functionality
1 parent 04bd508 commit 4ab3bef

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tests/test_pytest_plugin.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import textwrap
6-
import time
76
import typing as t
87

98
if t.TYPE_CHECKING:
@@ -13,6 +12,8 @@
1312

1413
from libtmux.server import Server
1514

15+
from libtmux._internal.waiter import wait_for_server_condition
16+
1617

1718
def test_plugin(
1819
pytester: pytest.Pytester,
@@ -132,9 +133,21 @@ def test_test_server_cleanup(TestServer: t.Callable[..., Server]) -> None:
132133
# Delete server and verify cleanup
133134
server.kill()
134135

135-
# Simply wait a short time rather than using the condition
136-
# since the server object is already killed
137-
time.sleep(0.1) # Give time for cleanup
136+
# Wait for the server to be fully cleaned up
137+
def is_server_dead(srv: Server) -> bool:
138+
try:
139+
return not srv.is_alive()
140+
except Exception:
141+
# If server is cleaned up, calling is_alive() may raise an exception
142+
return True
143+
144+
wait_for_server_condition(
145+
server,
146+
is_server_dead,
147+
timeout=0.5,
148+
interval=0.1,
149+
raises=False,
150+
)
138151

139152
# Create new server to verify old one was cleaned up
140153
new_server = TestServer()

0 commit comments

Comments
 (0)