async def test_execute_task__cancelled_stopped(self, *, agent): coro = FutureMock() coro.side_effect = asyncio.CancelledError() await agent.stop() with pytest.raises(asyncio.CancelledError): await agent._execute_task(coro, Mock(name='aref', autospec=Actor)) coro.assert_awaited()
async def test_execute_actor__raising(self, *, agent): agent._on_error = AsyncMock(name='on_error') agent.log = Mock(name='log', autospec=CompositeLogger) aref = Mock( name='aref', autospec=Actor, crash=AsyncMock(), ) agent.supervisor = Mock(name='supervisor') coro = FutureMock() exc = coro.side_effect = KeyError('bar') await agent._execute_actor(coro, aref) coro.assert_awaited() aref.crash.assert_called_once_with(exc) agent.supervisor.wakeup.assert_called_once_with() agent._on_error.assert_called_once_with(agent, exc) agent._on_error = None await agent._execute_actor(coro, aref)
async def test_execute_actor__cancelled_running(self, *, agent): agent._on_error = AsyncMock(name="on_error") agent.log = Mock(name="log", autospec=CompositeLogger) aref = Mock( name="aref", autospec=Actor, crash=AsyncMock(), ) agent.supervisor = Mock(name="supervisor") coro = FutureMock() exc = coro.side_effect = asyncio.CancelledError() await agent._execute_actor(coro, aref) coro.assert_awaited() aref.crash.assert_called_once_with(exc) agent.supervisor.wakeup.assert_called_once_with() agent._on_error.assert_not_called() agent._on_error = None await agent._execute_actor(coro, aref)
async def test_execute_task__cancelled_running(self, *, agent): coro = FutureMock() coro.side_effect = asyncio.CancelledError() await agent._execute_task(coro, Mock(name='aref', autospec=Actor)) coro.assert_awaited()