test: simplify rsync daemon startup, capture stderr
This commit is contained in:
@@ -274,13 +274,11 @@ def run_profile(profile_name, source_dir, dest_dir):
|
|||||||
rsync_port = find_free_port()
|
rsync_port = find_free_port()
|
||||||
rsyncd_conf = os.path.join(tempfile.gettempdir(), f"rsyncd-{rsync_port}.conf")
|
rsyncd_conf = os.path.join(tempfile.gettempdir(), f"rsyncd-{rsync_port}.conf")
|
||||||
with open(rsyncd_conf, "w") as f:
|
with open(rsyncd_conf, "w") as f:
|
||||||
f.write(f"""use chroot = no
|
f.write(f"""port = {rsync_port}
|
||||||
max connections = 5
|
|
||||||
read only = yes
|
read only = yes
|
||||||
port = {rsync_port}
|
|
||||||
|
|
||||||
[source]
|
[source]
|
||||||
path = {source_dir}
|
path = {source_dir}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
rsync_daemon = None
|
rsync_daemon = None
|
||||||
@@ -289,13 +287,13 @@ path = {source_dir}
|
|||||||
["rsync", "--daemon", "--no-detach", f"--config={rsyncd_conf}"],
|
["rsync", "--daemon", "--no-detach", f"--config={rsyncd_conf}"],
|
||||||
stdout=subprocess.DEVNULL, stderr=None
|
stdout=subprocess.DEVNULL, stderr=None
|
||||||
)
|
)
|
||||||
for _ in range(25):
|
for _ in range(50):
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
if rsync_daemon.poll() is not None:
|
if rsync_daemon.poll() is not None:
|
||||||
print(f" rsync daemon exited prematurely (rc={rsync_daemon.returncode})")
|
print(f" rsync daemon exited (rc={rsync_daemon.returncode})")
|
||||||
raise RuntimeError("rsync daemon failed to start")
|
raise RuntimeError("rsync daemon failed to start")
|
||||||
try:
|
try:
|
||||||
with socket.create_connection(("127.0.0.1", rsync_port), timeout=0.5):
|
with socket.create_connection(("127.0.0.1", rsync_port), timeout=0.3):
|
||||||
break
|
break
|
||||||
except (ConnectionRefusedError, OSError):
|
except (ConnectionRefusedError, OSError):
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user