summaryrefslogtreecommitdiff
path: root/test/fs.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/fs.py')
-rw-r--r--test/fs.py40
1 files changed, 31 insertions, 9 deletions
diff --git a/test/fs.py b/test/fs.py
index 98767a41..74c958ce 100644
--- a/test/fs.py
+++ b/test/fs.py
@@ -47,6 +47,7 @@ def session(binary, root, name, *options, socket_name=None, file=None, tty=False
preexec = lambda: fcntl.ioctl(0, termios.TIOCSCTTY, 0)
if launch is not None:
args = [binary, *launch]
+ existing = set(root.glob('pardes-9p-*.sock'))
child = subprocess.Popen(args, cwd=root, env=env, stdin=slave,
stdout=slave if tty else subprocess.DEVNULL,
stderr=subprocess.PIPE, start_new_session=True,
@@ -55,7 +56,9 @@ def session(binary, root, name, *options, socket_name=None, file=None, tty=False
# Borrowed handles for input-driving probes, valid inside this context.
terminal.update(pid=child.pid, input_fd=master)
if launch is not None and socket_name is None:
- address = root / f'pardes-9p-{child.pid}.sock'
+ # Named by the session's pid: a terminal's session is forked
+ # off the process launched, which stays as its stub.
+ address = None
if slave is not None:
os.close(slave)
slave = None
@@ -68,7 +71,11 @@ def session(binary, root, name, *options, socket_name=None, file=None, tty=False
reader = threading.Thread(target=drain, daemon=True)
reader.start()
deadline = time.monotonic() + 10
- while not address.exists():
+ while address is None or not address.exists():
+ if address is None:
+ address = next(iter(set(root.glob('pardes-9p-*.sock')) - existing), None)
+ if address is not None:
+ continue
if child.poll() is not None:
raise AssertionError((args, child.returncode, child.stderr.read().decode()))
if time.monotonic() > deadline:
@@ -984,19 +991,24 @@ def python_repl_runs_one_line(binary):
def signal_cleans_up(binary):
- """A detached session told to stop by a signal unlinks its sockets."""
+ """A detached session told to stop by a signal unlinks its sockets. A
+ hangup is a terminal's end, not a session's: the daemon keeps it."""
for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP]:
with tempfile.TemporaryDirectory(prefix='pardes-sig-') as directory:
root = Path(directory)
seen = {}
with session(binary, root, 'sig', terminal=seen) as (client, address):
- detached = root / 'pardes-detached-sig.sock'
- assert address.exists() and detached.exists()
+ assert address.exists()
+ if sig == signal.SIGHUP:
+ os.kill(seen['pid'], sig)
+ time.sleep(.3)
+ assert address.exists() and client.read('/index'), 'a hangup ended a kept session'
+ sig = signal.SIGTERM
os.kill(seen['pid'], sig)
deadline = time.monotonic() + 5
- while (address.exists() or detached.exists()) and time.monotonic() < deadline:
+ while address.exists() and time.monotonic() < deadline:
time.sleep(.01)
- assert not address.exists() and not detached.exists(), (sig, list(root.iterdir()))
+ assert not address.exists(), (sig, list(root.iterdir()))
def odd_paths(binary):
@@ -1885,6 +1897,7 @@ def test(binary, quic=False):
cooked = termios.tcgetattr(slave)
env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_')}
env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), TERM='xterm-256color', PARDES_NOTIME='1')
+ existing = set(root.glob('pardes-9p-*.sock'))
killed = subprocess.Popen([binary, '--tty', 'x.txt'], cwd=root, env=env,
stdin=slave, stdout=slave, stderr=subprocess.DEVNULL,
start_new_session=True,
@@ -1897,12 +1910,21 @@ def test(binary, quic=False):
if select.select([master], [], [], .1)[0]:
seen += os.read(master, 65536)
time.sleep(.3)
- own_socket = root / f'pardes-9p-{killed.pid}.sock'
- assert own_socket.exists()
+ # The session's own, named by its pid: forked off the
+ # launched process, which stays as its stub.
+ own_socket, = set(root.glob('pardes-9p-*.sock')) - existing
assert not dead_socket.exists()
assert live_socket.exists()
killed.send_signal(sig)
assert killed.wait(timeout=5) == -sig
+ if sig == signal.SIGHUP:
+ # A hangup is the terminal's end: the session carries on
+ # detached (the daemon keeps it) until told to end.
+ assert own_socket.exists(), own_socket
+ os.kill(int(own_socket.name[len('pardes-9p-'):-len('.sock')]), signal.SIGTERM)
+ deadline = time.monotonic() + 5
+ while own_socket.exists() and time.monotonic() < deadline:
+ time.sleep(.01)
assert not own_socket.exists(), own_socket
while select.select([master], [], [], .2)[0]:
try: