Skip to content

Commit db1a2cf

Browse files
committed
fix: wait for git daemon to listen before connecting
Properly wait instead of hardcoding a short sleep. Fixes #1676
1 parent 3481da9 commit db1a2cf

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

test/lib/helper.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import os
3333
import os.path as osp
3434
from stat import S_ISLNK, ST_MODE
35+
import socket
3536
import subprocess
3637
import sys
3738
import tempfile
@@ -218,8 +219,15 @@ def git_daemon_launched(base_path, ip, port):
218219
base_path=base_path,
219220
as_process=True,
220221
)
221-
# Yes, I know... fortunately, this is always going to work if sleep time is just large enough.
222-
time.sleep(1.0 if sys.platform == "win32" else 0.5)
222+
223+
# Wait until git daemon listens for connections.
224+
for _attempt in range(1, 30):
225+
try:
226+
socket.create_connection((ip, port), timeout=30).close()
227+
break
228+
except ConnectionRefusedError:
229+
time.sleep(0.5)
230+
223231
except Exception as ex:
224232
msg = textwrap.dedent(
225233
"""

0 commit comments

Comments
 (0)