120 lines
2.8 KiB
Python
120 lines
2.8 KiB
Python
'''
|
|
That "native" runtime-hackin toolset better be dang useful!
|
|
|
|
Verify the funtion of a variety of "developer-experience" tools we
|
|
offer from the `.devx` sub-pkg:
|
|
|
|
- use of the lovely `stackscope` for dumping actor `trio`-task trees
|
|
during operation and hangs.
|
|
|
|
TODO:
|
|
- demonstration of `CallerInfo` call stack frame filtering such that
|
|
for logging and REPL purposes a user sees exactly the layers needed
|
|
when debugging a problem inside the stack vs. in their app.
|
|
|
|
'''
|
|
import os
|
|
import signal
|
|
import time
|
|
|
|
from .conftest import (
|
|
expect,
|
|
assert_before,
|
|
# in_prompt_msg,
|
|
)
|
|
|
|
|
|
def test_shield_pause(
|
|
spawn,
|
|
):
|
|
'''
|
|
Verify the `tractor.pause()/.post_mortem()` API works inside an
|
|
already cancelled `trio.CancelScope` and that you can step to the
|
|
next checkpoint wherein the cancelled will get raised.
|
|
|
|
'''
|
|
child = spawn(
|
|
'shield_hang_in_sub'
|
|
)
|
|
expect(
|
|
child,
|
|
'Yo my child hanging..?',
|
|
)
|
|
assert_before(
|
|
child,
|
|
[
|
|
'Entering shield sleep..',
|
|
'Enabling trace-trees on `SIGUSR1` since `stackscope` is installed @',
|
|
]
|
|
)
|
|
|
|
script_pid: int = child.pid
|
|
print(
|
|
f'Sending SIGUSR1 to {script_pid}\n'
|
|
f'(kill -s SIGUSR1 {script_pid})\n'
|
|
)
|
|
os.kill(
|
|
script_pid,
|
|
signal.SIGUSR1,
|
|
)
|
|
time.sleep(0.2)
|
|
expect(
|
|
child,
|
|
# end-of-tree delimiter
|
|
"end-of-\('root'",
|
|
)
|
|
assert_before(
|
|
child,
|
|
[
|
|
# 'Srying to dump `stackscope` tree..',
|
|
# 'Dumping `stackscope` tree for actor',
|
|
"('root'", # uid line
|
|
|
|
# TODO!? this used to show?
|
|
# -[ ] mk reproducable for @oremanj?
|
|
#
|
|
# parent block point (non-shielded)
|
|
# 'await trio.sleep_forever() # in root',
|
|
]
|
|
)
|
|
expect(
|
|
child,
|
|
# end-of-tree delimiter
|
|
"end-of-\('hanger'",
|
|
)
|
|
assert_before(
|
|
child,
|
|
[
|
|
# relay to the sub should be reported
|
|
'Relaying `SIGUSR1`[10] to sub-actor',
|
|
|
|
"('hanger'", # uid line
|
|
|
|
# TODO!? SEE ABOVE
|
|
# hanger LOC where it's shield-halted
|
|
# 'await trio.sleep_forever() # in subactor',
|
|
]
|
|
)
|
|
|
|
# simulate the user sending a ctl-c to the hanging program.
|
|
# this should result in the terminator kicking in since
|
|
# the sub is shield blocking and can't respond to SIGINT.
|
|
os.kill(
|
|
child.pid,
|
|
signal.SIGINT,
|
|
)
|
|
expect(
|
|
child,
|
|
'Shutting down actor runtime',
|
|
timeout=6,
|
|
)
|
|
assert_before(
|
|
child,
|
|
[
|
|
'raise KeyboardInterrupt',
|
|
# 'Shutting down actor runtime',
|
|
'#T-800 deployed to collect zombie B0',
|
|
"'--uid', \"('hanger',",
|
|
]
|
|
)
|