Update debugger tests to expect new pformatting

Mostly the result of the `RemoteActorError.pformat()` and our
new `_pause/crash_msg: str`s which include the `trio.Task.__repr__()`
in the `log.pdb()` message.

Obvi use the `in_prompt_msg()` to accomplish where not used prior.

ToDo later:
-[ ] still some outstanding questions on how detailed inceptions
   should look, eg. in `test_multi_nested_subactors_error_through_nurseries()`
  |_maybe we should be more pedantic at checking `.src_uid` vs.
    `.relay_uid` fields?
-[ ] staged a placeholder test for verifying correct call-stack frame on
   crash handler REPL entry.
-[ ] also need a test to verify that you can't pause from an already paused actor task
   such as can happen if you try to step through runtime code that has
   a recurrent entry to `._debug.pause()`.
runtime_to_msgspec
Tyler Goodlet 2024-05-22 15:01:31 -04:00
parent d15e73557a
commit 702dfe47d5
1 changed files with 78 additions and 30 deletions

View File

@ -146,9 +146,10 @@ def in_prompt_msg(
log/REPL output for a given `pdb` interact point. log/REPL output for a given `pdb` interact point.
''' '''
__tracebackhide__: bool = False
for part in parts: for part in parts:
if part not in prompt: if part not in prompt:
if pause_on_false: if pause_on_false:
import pdbp import pdbp
pdbp.set_trace() pdbp.set_trace()
@ -167,6 +168,7 @@ def assert_before(
**kwargs, **kwargs,
) -> None: ) -> None:
__tracebackhide__: bool = False
# as in before the prompt end # as in before the prompt end
before: str = str(child.before.decode()) before: str = str(child.before.decode())
@ -219,7 +221,10 @@ def ctlc(
], ],
ids=lambda item: f'{item[0]} -> {item[1]}', ids=lambda item: f'{item[0]} -> {item[1]}',
) )
def test_root_actor_error(spawn, user_in_out): def test_root_actor_error(
spawn,
user_in_out,
):
''' '''
Demonstrate crash handler entering pdb from basic error in root actor. Demonstrate crash handler entering pdb from basic error in root actor.
@ -465,8 +470,12 @@ def test_subactor_breakpoint(
child.expect(PROMPT) child.expect(PROMPT)
before = str(child.before.decode()) before = str(child.before.decode())
assert "RemoteActorError: ('breakpoint_forever'" in before assert in_prompt_msg(
assert 'bdb.BdbQuit' in before before,
['RemoteActorError:',
"('breakpoint_forever'",
'bdb.BdbQuit',]
)
if ctlc: if ctlc:
do_ctlc(child) do_ctlc(child)
@ -478,8 +487,12 @@ def test_subactor_breakpoint(
child.expect(pexpect.EOF) child.expect(pexpect.EOF)
before = str(child.before.decode()) before = str(child.before.decode())
assert "RemoteActorError: ('breakpoint_forever'" in before assert in_prompt_msg(
assert 'bdb.BdbQuit' in before before,
['RemoteActorError:',
"('breakpoint_forever'",
'bdb.BdbQuit',]
)
@has_nested_actors @has_nested_actors
@ -747,8 +760,9 @@ def test_multi_daemon_subactors(
# boxed error raised in root task # boxed error raised in root task
# "Attaching to pdb in crashed actor: ('root'", # "Attaching to pdb in crashed actor: ('root'",
_crash_msg, _crash_msg,
"('root'", "('root'", # should attach in root
"_exceptions.RemoteActorError: ('name_error'", "_exceptions.RemoteActorError:", # with an embedded RAE for..
"('name_error'", # the src subactor which raised
] ]
) )
@ -849,10 +863,11 @@ def test_multi_nested_subactors_error_through_nurseries(
# https://github.com/goodboy/tractor/issues/320 # https://github.com/goodboy/tractor/issues/320
# ctlc: bool, # ctlc: bool,
): ):
"""Verify deeply nested actors that error trigger debugger entries '''
Verify deeply nested actors that error trigger debugger entries
at each actor nurserly (level) all the way up the tree. at each actor nurserly (level) all the way up the tree.
""" '''
# NOTE: previously, inside this script was a bug where if the # NOTE: previously, inside this script was a bug where if the
# parent errors before a 2-levels-lower actor has released the lock, # parent errors before a 2-levels-lower actor has released the lock,
# the parent tries to cancel it but it's stuck in the debugger? # the parent tries to cancel it but it's stuck in the debugger?
@ -872,22 +887,31 @@ def test_multi_nested_subactors_error_through_nurseries(
except EOF: except EOF:
break break
assert_before(child, [ assert_before(
child,
[ # boxed source errors
"NameError: name 'doggypants' is not defined",
"tractor._exceptions.RemoteActorError:",
"('name_error'",
"bdb.BdbQuit",
# boxed source errors # first level subtrees
"NameError: name 'doggypants' is not defined", # "tractor._exceptions.RemoteActorError: ('spawner0'",
"tractor._exceptions.RemoteActorError: ('name_error'", "src_uid=('spawner0'",
"bdb.BdbQuit",
# first level subtrees # "tractor._exceptions.RemoteActorError: ('spawner1'",
"tractor._exceptions.RemoteActorError: ('spawner0'",
# "tractor._exceptions.RemoteActorError: ('spawner1'",
# propagation of errors up through nested subtrees # propagation of errors up through nested subtrees
"tractor._exceptions.RemoteActorError: ('spawn_until_0'", # "tractor._exceptions.RemoteActorError: ('spawn_until_0'",
"tractor._exceptions.RemoteActorError: ('spawn_until_1'", # "tractor._exceptions.RemoteActorError: ('spawn_until_1'",
"tractor._exceptions.RemoteActorError: ('spawn_until_2'", # "tractor._exceptions.RemoteActorError: ('spawn_until_2'",
]) # ^-NOTE-^ old RAE repr, new one is below with a field
# showing the src actor's uid.
"src_uid=('spawn_until_0'",
"relay_uid=('spawn_until_1'",
"src_uid=('spawn_until_2'",
]
)
@pytest.mark.timeout(15) @pytest.mark.timeout(15)
@ -1021,13 +1045,16 @@ def test_different_debug_mode_per_actor(
# msg reported back from the debug mode actor is processed. # msg reported back from the debug mode actor is processed.
# assert "tractor._exceptions.RemoteActorError: ('debugged_boi'" in before # assert "tractor._exceptions.RemoteActorError: ('debugged_boi'" in before
assert "tractor._exceptions.RemoteActorError: ('crash_boi'" in before
# the crash boi should not have made a debugger request but # the crash boi should not have made a debugger request but
# instead crashed completely # instead crashed completely
assert "tractor._exceptions.RemoteActorError: ('crash_boi'" in before assert_before(
assert "RuntimeError" in before child,
[
"tractor._exceptions.RemoteActorError:",
"src_uid=('crash_boi'",
"RuntimeError",
]
)
def test_pause_from_sync( def test_pause_from_sync(
@ -1046,13 +1073,15 @@ def test_pause_from_sync(
assert_before( assert_before(
child, child,
[ [
'`greenback` portal opened!',
# pre-prompt line # pre-prompt line
_pause_msg, "('root'", _pause_msg,
"<Task '__main__.main'",
"('root'",
] ]
) )
if ctlc: if ctlc:
do_ctlc(child) do_ctlc(child)
child.sendline('c') child.sendline('c')
child.expect(PROMPT) child.expect(PROMPT)
@ -1069,6 +1098,7 @@ def test_pause_from_sync(
if ctlc: if ctlc:
do_ctlc(child) do_ctlc(child)
child.sendline('c') child.sendline('c')
child.expect(PROMPT) child.expect(PROMPT)
assert_before( assert_before(
@ -1078,6 +1108,7 @@ def test_pause_from_sync(
if ctlc: if ctlc:
do_ctlc(child) do_ctlc(child)
child.sendline('c') child.sendline('c')
child.expect(PROMPT) child.expect(PROMPT)
# non-main thread case # non-main thread case
@ -1089,5 +1120,22 @@ def test_pause_from_sync(
if ctlc: if ctlc:
do_ctlc(child) do_ctlc(child)
child.sendline('c') child.sendline('c')
child.expect(pexpect.EOF) child.expect(pexpect.EOF)
# TODO!
def test_correct_frames_below_hidden():
'''
Ensure that once a `tractor.pause()` enages, when the user
inputs a "next"/"n" command the actual next line steps
and that using a "step"/"s" into the next LOC, particuarly
`tractor` APIs, you can step down into that code.
'''
...
def test_cant_pause_from_paused_task():
...