diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/daemon.py | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/test/daemon.py b/test/daemon.py index c53405db..e7fee37b 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -31,6 +31,7 @@ private HOME and runtime directory: """ import fcntl import os +import re import select import shutil import signal @@ -227,9 +228,10 @@ class Replica: """A replica's connection (src/wire.zig): length-prefixed messages, a tag byte and a little-endian u32 length. It is a near client: its first word after the hello says so.""" - WIRE = 20 + WIRE = 21 def __init__(self, path, timeout=10): + self.path, self.timeout = path, timeout self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.s.settimeout(timeout) self.s.connect(os.fspath(path)) @@ -250,11 +252,12 @@ class Replica: tag, n = struct.unpack('<BI', self.take(5)) return tag, self.take(n) - def hello(self, session, build): + def hello(self, session, build, wire=None): """('welcome', pid, name) or ('refused', why); a welcome's dump - is read, whole.""" + is read, whole. A daemon of another replica protocol (an older + build's, across an Upgrade) is dialled again in its own.""" name = session.encode() - self.send(0x01, struct.pack('<HQH', self.WIRE, build, len(name)) + name + b'\xff') + self.send(0x01, struct.pack('<HQH', wire or self.WIRE, build, len(name)) + name + b'\xff') self.send(0x06, b'\x00') tag, body = self.read() if tag == 0x01: @@ -269,7 +272,13 @@ class Replica: return 'welcome', pid, body[6:6 + n].decode() assert tag == 0x02, (tag, body) n, = struct.unpack_from('<H', body) - return 'refused', body[2:2 + n].decode() + why = body[2:2 + n].decode() + other = re.search(r'replica protocol \d+, and this daemon (\d+)', why) + if other and wire is None: + self.close() + self.__init__(self.path, self.timeout) + return self.hello(session, build, int(other.group(1))) + return 'refused', why def ping(self, value): """One round trip, in ms (the session's units and terminal @@ -1469,7 +1478,7 @@ def upgrades(old, new): assert client.read(f'/pane/{text}/body') == b'one\ntwo\nunsaved\n' client.write(f'/pane/{shell}/pty/data', b'sleep 1000; echo done-after-upgrade\r') sleeper = wait_for('the sleep', lambda: [p for p in processes(root) if cmdline(p)[:2] == [b'sleep', b'1000']])[0] - # A second terminal: a view of its own. + # A second terminal: a view of its own (an older build's), or a client. term2 = Term(30, 100) stub2 = term2.spawn([str(binary), '--attach=work'], env) started.append(stub2.pid) @@ -1510,7 +1519,7 @@ def upgrades(old, new): wait_for('the daemon on the new build', lambda: exe_of(daemon) == (str(binary), True)) else: wait_for('the daemon exec\'d again', lambda: any(a.startswith(b'--upgraded=') for a in cmdline(daemon))) - assert alive(daemon) and stub.poll() is None and stub2.poll() is None + assert alive(daemon) and stub.poll() is None # A replica of the old build is told why it is let go, after what it # was sent (units, terminals). tag, body = replica.read() @@ -1519,7 +1528,8 @@ def upgrades(old, new): assert tag == 0x02 and b'upgrading to another build' in body, (tag, body) replica.close() stale.wait(timeout=30) - assert b'upgrade this client too' in term3.text(), term3.text()[-400:] + # (Across a change of the replica protocol, it says that instead.) + assert b'upgrade this client too' in term3.text() or b'run the same pardes at both ends' in term3.text(), term3.text()[-400:] term3.close() print('upgrade: a replica client of the old build was let go, dialled again and was told to upgrade too') # The old image's prompt files swept, the new one's made. @@ -1529,8 +1539,11 @@ def upgrades(old, new): # (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.) + # A second terminal an older build kept as a view of its own is let + # go (its terminal and its stub's pipe): two fewer again. def level(): - return fds_before[0] - 2 + min(state_fds(session), 1) - state_before, fds_before[1] + gone = 2 if stub2.poll() is not None else 0 + return fds_before[0] - 2 - gone + min(state_fds(session), 1) - state_before, fds_before[1] try: wait_for('the fds level', lambda: (fds(session), fds(daemon)) == level(), timeout=5) except TimeoutError: @@ -1544,7 +1557,10 @@ def upgrades(old, new): assert alive(shell_pid) and ppid(shell_pid) == session and alive(sleeper) # Both terminals drawn again, each its own view. wait_for('the first terminal redrawn', lambda: b'\x1b[?1049h' in term.text()[before[0]:]) - wait_for('the second terminal redrawn', lambda: b'\x1b[?1049h' in term2.text()[before[1]:]) + # The second: a client again, or, a view of an older build's own, let + # go (a session shows one frontend of its own now), its stub told. + wait_for('the second terminal redrawn or let go', lambda: b'\x1b[?1049h' in term2.text()[before[1]:] or + (stub2.poll() is not None and b'detached from' in term2.text())) wait_for('the word said', lambda: 'Upgrade: now pardes' in screen_text(client)) # The daemon lists the session under its new build. said = Replica(root / 'pardes-replica.sock').hello('work', new_build) @@ -1553,7 +1569,7 @@ def upgrades(old, new): assert said[0] == 'refused' and 'another build' in said[1], said os.kill(sleeper, signal.SIGTERM) wait_for('the shell carrying on', lambda: b'done-after-upgrade\n' in client.read(f'/pane/{shell}/body')) - print(f'upgrade: session {session}, its daemon {daemon}, shell {shell_pid} and two terminals on the new build ' + print(f'upgrade: session {session}, its daemon {daemon}, shell {shell_pid} and its terminal on the new build (a second one an older build kept let go, or a client again) ' f'(the word to its 9P again: {took * 1000:.0f} ms); the edit, its undo and the job kept') # A build that cannot load the dump: back to the one running (a copy |
