summaryrefslogtreecommitdiff
path: root/test/fs.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/fs.py')
-rw-r--r--test/fs.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/test/fs.py b/test/fs.py
index b90983d4..53a9d4df 100644
--- a/test/fs.py
+++ b/test/fs.py
@@ -3,6 +3,7 @@ import contextlib
import fcntl
import json
import os
+import signal
from pathlib import Path
import subprocess
import struct
@@ -245,7 +246,7 @@ def discovery(binary, embedded=False):
client.write('/focus', b'99999\n')
raise AssertionError('focus took a serial no pane has')
except OSError as refused:
- assert 'no such window' in str(refused), refused
+ assert 'no such pane' in str(refused), refused
# /ctl reads the settings as a write takes them and takes the
# session's builtins; a pane's ctl takes the pane's.
settings = client.read('/ctl')
@@ -424,10 +425,27 @@ def exit_answers(binary):
raise AssertionError("Exit did not quit the editor")
+def signal_cleans_up(binary):
+ """A detached session told to stop by a signal unlinks its sockets."""
+ 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()
+ os.kill(seen['pid'], sig)
+ deadline = time.monotonic() + 5
+ while (address.exists() or detached.exists()) and time.monotonic() < deadline:
+ time.sleep(.01)
+ assert not address.exists() and not detached.exists(), (sig, list(root.iterdir()))
+
+
def test(binary, quic=False):
started = time.monotonic()
run_file(binary)
exit_answers(binary)
+ signal_cleans_up(binary)
for options, message in [
(['--fs'], b'no such option'),
(['--fs9'], b'no such option'),
@@ -602,23 +620,23 @@ def test(binary, quic=False):
assert old.read_fid(held_screen, count=1) == b'{'
old.write('/pane/1/body', b'changed after dump\n', truncate=True)
# Unsaved text is asked about once, as Exit asks; the second
- # Restore goes ahead.
+ # Restore goes ahead, and is answered before the hang-up.
try:
execute(old, control, 'Restore ' + str(saved))
except OSError as refused:
assert 'Modified' in str(refused), refused
assert old.read('/pane/1/body') == b'changed after dump\n'
- try:
- execute(old, control, 'Restore ' + str(saved))
- except (EOFError, ConnectionResetError, BrokenPipeError):
- pass
+ execute(old, control, 'Restore ' + str(saved))
+ # Refused while the connections are cut, or cut already.
try:
old.read_fid(held_body)
- except (EOFError, ConnectionResetError, BrokenPipeError):
+ except (EOFError, OSError):
pass
else:
raise AssertionError('Restore left an old body fid usable')
with Client(address) as restored:
+ # The new log names its panes, then where they came from.
+ assert restored.read('/log').endswith(b'\nrestore ' + str(saved).encode() + b'\n'), restored.read('/log')
restored_ids = [int(row.split()[0]) for row in restored.read('/index').splitlines()]
assert len(restored_ids) == 2 and old_ids.isdisjoint(restored_ids), restored_ids
file_id, control_id = restored_ids