summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/daemon.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/test/daemon.py b/test/daemon.py
index 33806575..b0c02690 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -198,6 +198,25 @@ def fds(pid):
return -1
+def links(pid):
+ """What its fds are open on."""
+ if not procfs:
+ return [line.split()[-1] for line in subprocess.run(['procstat', '-f', str(pid)], capture_output=True,
+ text=True).stdout.splitlines()[1:] if line.split()]
+ out = []
+ for fd in os.listdir(f'/proc/{pid}/fd'):
+ try:
+ out.append(os.readlink(f'/proc/{pid}/fd/{fd}'))
+ except OSError:
+ pass
+ return out
+
+
+def state_fds(pid):
+ """Its fds on the state file, which a session keeps open (Db.zig)."""
+ return sum(1 for path in links(pid) if path.endswith('/pardes.xitdb'))
+
+
def semantics(binary):
"""What a replica's build must share with its session's (--version)."""
out = subprocess.run([binary, '--version'], capture_output=True, check=True).stdout.decode()
@@ -1463,6 +1482,7 @@ def upgrades(old, new):
os.write(term.master, b'\x1b[I')
wait_for('the newer build said', lambda: 'a newer pardes is installed' in screen_text(client))
fds_before = fds(session), fds(daemon)
+ state_before = state_fds(session)
rcs = sorted(Path('/tmp').glob(f'pardes-osc133-*-{session}-*'))
t = time.monotonic()
client.write('/ctl', b'Upgrade\n')
@@ -1497,13 +1517,15 @@ def upgrades(old, new):
wait_for('the prompt files level', lambda: len(list(Path('/tmp').glob(f'pardes-osc133-*-{session}-*'))) == len(rcs))
assert sorted(Path('/tmp').glob(f'pardes-osc133-*-{session}-*')) != rcs or not rcs
# Nothing kept that was not: the old binary let go, every fd back.
- # (The replicas' connections are two fewer.)
- level = fds_before[0] - 2, fds_before[1]
+ # (The replicas' connections are two fewer; the state file's one
+ # more after a build that opened Recent's file for each use, and
+ # only one: a session holds it once.)
+ def level():
+ return fds_before[0] - 2 + min(state_fds(session), 1) - state_before, fds_before[1]
try:
- wait_for('the fds level', lambda: (fds(session), fds(daemon)) == level, timeout=5)
+ wait_for('the fds level', lambda: (fds(session), fds(daemon)) == level(), timeout=5)
except TimeoutError:
- raise AssertionError(('fds', level, (fds(session), fds(daemon)),
- os.listdir(f'/proc/{session}/fd') if procfs else None))
+ raise AssertionError(('fds', level(), (fds(session), fds(daemon)), links(session)))
# The edit and its undo.
assert client.read(f'/pane/{text}/body') == b'one\ntwo\nunsaved\n'
assert any(row.split()[0] == str(text).encode() and row.split()[2] == b'1' for row in client.read('/index').splitlines()), client.read('/index')