-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for #265: "msg sent before stream opened"
This always triggered the mentioned race condition. We need to figure out the best approach to avoid this case.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
''' | ||
``async with ():`` inlined context-stream cancellation testing. | ||
Verify the we raise errors when streams are opened prior to sync-opening | ||
a ``tractor.Context`` beforehand. | ||
''' | ||
import trio | ||
from trio.lowlevel import current_task | ||
import tractor | ||
|
||
|
||
@tractor.context | ||
async def never_open_stream( | ||
|
||
ctx: tractor.Context, | ||
|
||
) -> None: | ||
'''Bidir streaming endpoint which will stream | ||
back any sequence it is sent item-wise. | ||
''' | ||
await ctx.started() | ||
await trio.sleep_forever() | ||
|
||
|
||
def test_no_far_end_stream_opened(): | ||
''' | ||
This should exemplify the bug from: | ||
https://github.com/goodboy/tractor/issues/265 | ||
''' | ||
async def main(): | ||
async with tractor.open_nursery() as n: | ||
portal = await n.start_actor( | ||
'starts_no_stream', | ||
enable_modules=[__name__], | ||
) | ||
|
||
async with ( | ||
portal.open_context( | ||
never_open_stream,) as (ctx, sent), | ||
ctx.open_stream() as stream, | ||
): | ||
assert sent is None | ||
|
||
# XXX: so the question is whether | ||
# this should error if the far end | ||
# has not yet called `ctx.open_stream()`? | ||
# If we decide to do that we need a synchronization | ||
# message which is sent from that call? | ||
await stream.send('yo') | ||
|
||
trio.run(main) |