From 706a4b761b6ce68346602ce9ca79df0983cb1977 Mon Sep 17 00:00:00 2001 From: goodboy Date: Tue, 24 Feb 2026 20:28:21 -0500 Subject: [PATCH] Add 6sec timeout around `test_simple_rpc` suite for macos --- tests/test_2way.py | 94 ++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 41 deletions(-) diff --git a/tests/test_2way.py b/tests/test_2way.py index db3be4d9..f5a59cfe 100644 --- a/tests/test_2way.py +++ b/tests/test_2way.py @@ -1,15 +1,25 @@ -""" -Bidirectional streaming. +''' +Audit the simplest inter-actor bidirectional (streaming) +msg patterns. -""" +''' +from __future__ import annotations +from typing import ( + Callable, + TYPE_CHECKING, +) import pytest import trio import tractor +if TYPE_CHECKING: + from tractor import ( + Portal, + ) + @tractor.context async def simple_rpc( - ctx: tractor.Context, data: int, @@ -39,15 +49,14 @@ async def simple_rpc( @tractor.context async def simple_rpc_with_forloop( - ctx: tractor.Context, data: int, ) -> None: - """Same as previous test but using ``async for`` syntax/api. - - """ + ''' + Same as previous test but using `async for` syntax/api. + ''' # signal to parent that we're up await ctx.started(data + 1) @@ -74,56 +83,59 @@ async def simple_rpc_with_forloop( 'server_func', [simple_rpc, simple_rpc_with_forloop], ) -def test_simple_rpc(server_func, use_async_for): +def test_simple_rpc( + server_func: Callabe, + use_async_for: bool, +): ''' The simplest request response pattern. ''' async def main(): - async with tractor.open_nursery() as n: + with trio.fail_after(6): + async with tractor.open_nursery() as an: + portal: Portal = await an.start_actor( + 'rpc_server', + enable_modules=[__name__], + ) - portal = await n.start_actor( - 'rpc_server', - enable_modules=[__name__], - ) + async with portal.open_context( + server_func, # taken from pytest parameterization + data=10, + ) as (ctx, sent): - async with portal.open_context( - server_func, # taken from pytest parameterization - data=10, - ) as (ctx, sent): + assert sent == 11 - assert sent == 11 + async with ctx.open_stream() as stream: - async with ctx.open_stream() as stream: + if use_async_for: - if use_async_for: - - count = 0 - # receive msgs using async for style - print('ping') - await stream.send('ping') - - async for msg in stream: - assert msg == 'pong' + count = 0 + # receive msgs using async for style print('ping') await stream.send('ping') - count += 1 - if count >= 9: - break + async for msg in stream: + assert msg == 'pong' + print('ping') + await stream.send('ping') + count += 1 - else: - # classic send/receive style - for _ in range(10): + if count >= 9: + break - print('ping') - await stream.send('ping') - assert await stream.receive() == 'pong' + else: + # classic send/receive style + for _ in range(10): - # stream should terminate here + print('ping') + await stream.send('ping') + assert await stream.receive() == 'pong' - # final context result(s) should be consumed here in __aexit__() + # stream should terminate here - await portal.cancel_actor() + # final context result(s) should be consumed here in __aexit__() + + await portal.cancel_actor() trio.run(main)