diff options
Diffstat (limited to 'packages/meshbay-cli/tests/test_ctrl_c.py')
| -rw-r--r-- | packages/meshbay-cli/tests/test_ctrl_c.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/meshbay-cli/tests/test_ctrl_c.py b/packages/meshbay-cli/tests/test_ctrl_c.py new file mode 100644 index 0000000..53a798a --- /dev/null +++ b/packages/meshbay-cli/tests/test_ctrl_c.py @@ -0,0 +1,34 @@ +""" +Ctrl+C stops the client at once, whatever its loop is waiting for. + +On Windows the client runs a selector loop (aiortc's ICE needs one), and a +console event does not interrupt select(): Ctrl+C waited for the loop's next +timer — half a minute in `chat --follow` between pings. +""" + +import sys +import time + +from console import ctrl_c, interruptible + +IDLE = ("import asyncio, sys\n" + "from meshbay_cli.__main__ import loop_factory\n" + "print('ready', flush=True)\n" + "try:\n" + " asyncio.run(asyncio.sleep(60), loop_factory=loop_factory())\n" + "except KeyboardInterrupt:\n" + " sys.exit(130)\n") + + +def test_ctrl_c_wakes_an_idle_client_at_once(): + proc = interruptible([sys.executable, "-c", IDLE], None) + try: + assert proc.stdout.readline().strip() == "ready", proc.stderr.read() + started = time.monotonic() + ctrl_c(proc) + proc.wait(timeout=30) + assert proc.returncode == 130, proc.stderr.read() + assert time.monotonic() - started < 5 + finally: + if proc.poll() is None: + proc.kill() |