async def test_child_heartbeat_started(event_loop): up_read, up_write = os.pipe() down_read, down_write = os.pipe() os.close(up_write) os.close(down_read) child = Child(up_read, down_write, [], "1") child.loop = event_loop child._started = True sp = StreamProtocol() sp.reader = asyncio.StreamReader() async def reset(): sp.reader.feed_data(protocols.PING) child._started = False reset_task = asyncio.Task(reset()) with mock.patch( "blackhole.streams.StreamProtocol", return_value=sp), mock.patch( "asyncio.Task") as mock_task, mock.patch( "blackhole.child.Child._start") as mock_start, mock.patch( "blackhole.child.Child.stop") as mock_stop: await child.heartbeat() reset_task.cancel() assert mock_task.called is True assert mock_start.called is True assert mock_stop.called is True
async def test_child_heartbeat_started(event_loop): up_read, up_write = os.pipe() down_read, down_write = os.pipe() os.close(up_write) os.close(down_read) child = Child(up_read, down_write, [], "1") child.loop = event_loop child._started = True sp = StreamProtocol() sp.reader = asyncio.StreamReader() async def reset(): sp.reader.feed_data(protocols.PING) child._started = False reset_task = asyncio.Task(reset()) with mock.patch( "blackhole.streams.StreamProtocol", return_value=sp ), mock.patch("asyncio.Task") as mock_task, mock.patch( "blackhole.child.Child._start" ) as mock_start, mock.patch( "blackhole.child.Child.stop" ) as mock_stop: await child.heartbeat() reset_task.cancel() assert mock_task.called is True assert mock_start.called is True assert mock_stop.called is True
async def test_child_heartbeat_not_started(event_loop): up_read, up_write = os.pipe() down_read, down_write = os.pipe() os.close(up_write) os.close(down_read) child = Child(up_read, down_write, [], "1") child.loop = event_loop child._started = False with mock.patch("asyncio.Task") as mock_task, mock.patch( "blackhole.child.Child._start") as mock_start, mock.patch( "blackhole.child.Child.stop") as mock_stop: await child.heartbeat() assert mock_task.called is True assert mock_start.called is True assert mock_stop.called is True
async def test_child_heartbeat_not_started(event_loop): up_read, up_write = os.pipe() down_read, down_write = os.pipe() os.close(up_write) os.close(down_read) child = Child(up_read, down_write, [], "1") child.loop = event_loop child._started = False with mock.patch("asyncio.Task") as mock_task, mock.patch( "blackhole.child.Child._start" ) as mock_start, mock.patch("blackhole.child.Child.stop") as mock_stop: await child.heartbeat() assert mock_task.called is True assert mock_start.called is True assert mock_stop.called is True