summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/daemon.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/daemon.py b/test/daemon.py
index 5c075520..1be89d5b 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -978,6 +978,65 @@ def attach_upgrading(binary, rounds=6, dump=True):
shutil.rmtree(root, ignore_errors=True)
+def kept_views(binary):
+ """A view kept for its client's rejoin (views.away: a bye that says it
+ joins again, a client cut off behind, every client at an Upgrade) is
+ that client's for 30 s, then a join with no room takes it, in a session
+ nobody types in: a `new --detach` session at its four views (a client
+ attached, idle; raw replicas), two of them leaving to join again and
+ never coming back; a join at once is refused and told for how long, one
+ 31 s later, nothing typed in between, is welcomed."""
+ scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
+ scratch.mkdir(parents=True, exist_ok=True)
+ root = Path(tempfile.mkdtemp(prefix='rk-', dir=scratch))
+ env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k}
+ env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
+ TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1')
+ (root / 'config' / 'pardes').mkdir(parents=True)
+ (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n')
+ t = Term(30, 100)
+ rs = []
+ try:
+ out = subprocess.run([binary, 'new', '--detach=kv'], env=env, cwd=root, capture_output=True, timeout=30, stdin=subprocess.DEVNULL)
+ assert out.returncode == 0, out
+ a = t.spawn([binary, 'attach', 'kv'], env)
+ wait_for('the client drawn', lambda: b'\x1b[?1049h' in t.text(), timeout=30)
+ sock, build = root / 'pardes-replica.sock', semantics(binary)
+ while True:
+ r = Replica(sock)
+ said = r.hello('kv', build)
+ if said[0] != 'welcome':
+ break
+ rs.append(r)
+ assert said[0] == 'refused' and 'as many views' in said[1] and len(rs) >= 2, (said, len(rs))
+ for r in rs[:2]:
+ r.send(0x02, b'\x01')
+ r.close()
+ left = time.monotonic()
+ said = Replica(sock).hello('kv', build)
+ assert said[0] == 'refused' and re.search(r'as many views as it takes \(one is kept (\d+) s more for a client joining again\)', said[1]), said
+ print(f'kept views: {len(rs)} replicas and a client at the cap; two left to join again; a join at once refused: "{said[1]}"')
+ time.sleep(max(0, left + 31 - time.monotonic()))
+ said = Replica(sock).hello('kv', build)
+ assert said[0] == 'welcome', ('a view kept 31 s in an idle session, still kept', said)
+ assert a.poll() is None
+ print('kept views: a join 31 s after, nothing typed in between, took a kept view')
+ a.terminate()
+ a.wait(timeout=20)
+ assert subprocess.run([binary, 'kill', 'kv'], env=env, capture_output=True, timeout=30).returncode == 0
+ wait_for('nothing left', lambda: not [p for p in processes(root) if alive(p)], timeout=20)
+ finally:
+ for r in rs:
+ r.close()
+ for p in processes(root):
+ try:
+ os.kill(p, signal.SIGKILL)
+ except OSError:
+ pass
+ t.close()
+ shutil.rmtree(root, ignore_errors=True)
+
+
def pair_upgrade_views(binary):
"""PARDES_PAIR, two clients each in its own view (the pair's own terminal
and an attach), each with its own scroll and focus: the pair's scrolled
@@ -2566,6 +2625,7 @@ def main(binary, cycles):
pair(binary)
pair_rows(binary)
attach_upgrading(binary)
+ kept_views(binary)
pair_upgrade_views(binary)
manage(binary)
relink(binary)
@@ -3159,6 +3219,16 @@ def upgrades(old, new):
or b'run the same pardes at both ends' in term2.text())),
timeout=30)
wait_for('the word said', lambda: 'Upgrade: now pardes' in screen_text(client))
+ # Two clients' views kept at the Upgrade, with the time (views.away),
+ # whose clients never come back (the raw replica, the old build's):
+ # each its client's for 30 s, and the session's views all taken.
+ # The first join waits as long as its refusal says.
+ if keeps_views(old):
+ said = Replica(root / 'pardes-replica.sock').hello('work', new_build)
+ kept = re.search(r'one is kept (\d+) s more', said[1]) if said[0] == 'refused' else None
+ if kept:
+ time.sleep(int(kept.group(1)) + .5)
+ print(f'upgrade: two views kept for clients that never came back; the join waited {kept.group(1)} s for one, as its refusal said')
# The daemon lists the session under its new build.
said = Replica(root / 'pardes-replica.sock').hello('work', new_build)
assert said == ('welcome', session, 'work'), said
@@ -3298,6 +3368,12 @@ def knows_size(gui_binary):
return b'PARDES_JOIN_SIZE' in Path(gui_binary).read_bytes()
+def keeps_views(binary):
+ """Whether a build keeps its clients' views at an Upgrade with the time
+ each was kept (View.away_ns), so that the build after holds them."""
+ return b'away_ns' in Path(binary).read_bytes()
+
+
def knows_exec(binary):
"""Whether a build's client execs the build at its start path at an
Upgrade, for the view it is handed (PARDES_JOIN_VIEW)."""