Skip to content

Commit

Permalink
Change to new context-cancelled msg contents: pikerd is canceller
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed May 26, 2023
1 parent 024cf8b commit 4f67ac0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ async def _open_test_pikerd(
a different port then the default to allow testing alongside
a running stack.
Calls `.service._actor_runtime.maybe_open_pikerd()``
to boot the root actor / tractor runtime.
'''
import random
from piker.service import maybe_open_pikerd
Expand Down
24 changes: 16 additions & 8 deletions tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def test_runtime_boot(
):
'''
Verify we can boot the `pikerd` service stack using the
`open_test_pikerd` fixture helper and that registry address details
match up.
`open_test_pikerd()` fixture helper and that contact-registry
address details match up.
'''
async def main():
Expand All @@ -55,6 +55,9 @@ async def main():
assert pikerd_portal.channel.raddr == daemon_addr
assert pikerd_portal.channel.raddr == portal.channel.raddr

# no service tasks should be started
assert not services.service_tasks

trio.run(main)


Expand Down Expand Up @@ -121,8 +124,7 @@ def test_ensure_ems_in_paper_actors(
async def main():

# type declares
book: OrderClient
trades_stream: tractor.MsgStream
client: OrderClient
pps: dict[str, list[BrokerdPosition]]
accounts: list[str]
dialogs: dict[str, Status]
Expand All @@ -139,8 +141,8 @@ async def main():
mode='paper',
loglevel=loglevel,
) as (
book,
trades_stream,
client,
_, # trades_stream: tractor.MsgStream
pps,
accounts,
dialogs,
Expand All @@ -152,6 +154,9 @@ async def main():
assert not pps
assert not dialogs

assert not client._sent_orders
assert accounts

pikerd_subservices = ['emsd', 'samplerd']

async with (
Expand All @@ -169,10 +174,13 @@ async def main():
print('ALL SERVICES STARTED, terminating..')
await services.cancel_service('emsd')

# ensure we receive a remote cancellation error caused by the
# pikerd root actor since we used the `.cancel_service()` API
# above B)
with pytest.raises(
tractor._exceptions.ContextCancelled,
) as exc_info:
trio.run(main)

cancel_msg: str = '_emsd_main()` was remotely cancelled by its caller'
assert cancel_msg in exc_info.value.args[0]
cancelled_msg: str = "was remotely cancelled by remote actor (\'pikerd\'"
assert cancelled_msg in exc_info.value.args[0]

0 comments on commit 4f67ac0

Please sign in to comment.