emacs/test/lisp/jsonrpc-resources/server-anxious-nested.py
João Távora 36036e71c0 Jsonrpc: migrate more tests to Python subprocess fixtures
All tests now use 'jsonrpc--with-python-fixture' with a Python3
subprocess instead of the in-Emacs TCP server.  Changed the "harakiri"
method to be a request instead of a notification for to reduce chance of
"Sentinel hasn't run" warning.

The two in-Emacs-RPC-specific error tests ('errors-with--32601' and
'signals-an--32603-JSONRPC-error') are dropped with the fixture itself,
as the error paths they exercise are internal to the Emacs Lisp
dispatcher and have no direct Python equivalent.  They will have to be
re-done later on in other form.

* test/lisp/jsonrpc-resources/server-emacsrpc.py: New file.

* test/lisp/jsonrpc-resources/server-anxious-nested.py: Use new
  harakiri.

* test/lisp/jsonrpc-resources/server-emacsrpc.py: Use new harakiri.

* test/lisp/jsonrpc-resources/server-harakiri.py: Use new harakiri.

* test/lisp/jsonrpc-resources/server-remote-during-sync-1.py: Use new
  harakiri.

* test/lisp/jsonrpc-resources/server-remote-during-sync-2.py: Use new
  harakiri.

* test/lisp/jsonrpc-resources/server-remote-error.py: Use new harakiri.

* test/lisp/jsonrpc-resources/common.py (harakiri): New definition.

* test/lisp/jsonrpc-tests.el
(jsonrpc--with-python-fixture): Rework, move up.
(jsonrpc-connection-ready-p): Move up.
(jsonrpc--call-with-emacsrpc-fixture)
(jsonrpc--with-emacsrpc-fixture)
(errors-with--32601)
(signals-an--32603-JSONRPC-error): Remove.
(returns-3, times-out, doesnt-time-out, stretching-it-but-works)
(deferred-action-toolate, deferred-action-intime)
(deferred-action-complex-tests): Migrate to Python fixture.
(scontrol-remote-during-sync-1, scontrol-remote-during-sync-2)
(scontrol-anxious-nested, scontrol-remote-error)
(shutdown-clean-after-notification): Tweak.
2026-05-17 19:28:07 +01:00

52 lines
1.9 KiB
Python
Executable file

#!/usr/bin/env python3
"""Test server for scontrol-anxious-nested.
Choreography (exercises the anxious-continuation mechanism):
client -> server: LR1 (id=1)
server -> client: RR1 (id=1000)
server -> client: response LR1 "lr1-ok"
client -> server: LR2 (id=2)
server -> client: response LR2 "lr2-ok"
client -> server: response RR1 "lr2-ok"
LR2 should complete first, then RR1, then LR1.
"""
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
from common import read_msg, write_msg, log, harakiri
def main():
while True:
lr1 = read_msg()
if lr1 is None:
break
mid = lr1.get('id')
method = lr1.get('method')
log(f'<- {method or "(response)"} id={mid}')
if harakiri(lr1): break
elif method == 'LR1':
# Send RR1, then immediately respond to LR1 without awaiting
# anything. The response-to-LR1 will be queued as anxious on the
# client while its rdispatcher blocks waiting for LR2.
write_msg({'jsonrpc': '2.0', 'id': 1000,
'method': 'RR1', 'params': {}})
log('-> RR1 id=1000')
write_msg({'jsonrpc': '2.0', 'id': mid, 'result': 'lr1-ok'})
log(f'-> (response LR1) id={mid}')
# LR2 arrives next: the client's rdispatcher for RR1
# issues it as a nested sync request.
lr2 = read_msg()
fid = lr2.get('id') if lr2 else None
log(f'<- LR2 id={fid}')
write_msg({'jsonrpc': '2.0', 'id': fid, 'result': 'lr2-ok'})
log(f'-> (response LR2) id={fid}')
# Finally collect the RR1 response (rdispatcher return value).
rr1_resp = read_msg()
log(f'<- (response RR1) id={rr1_resp.get("id") if rr1_resp else None}')
if __name__ == '__main__':
main()