def test_stop_runtime_exception(): with mock.patch('blackhole.worker.Worker.start') as mock_start, \ mock.patch('os.kill', side_effect=ProcessLookupError): w = Worker([], []) w.chat_task = mock.Mock() w.heartbeat_task = mock.Mock() w.rtransport = mock.Mock() w.wtransport = mock.Mock() w.pid = 123 w.stop() assert mock_start.called is True
async def test_worker_ping_pong(unused_tcp_port): aserver = server("127.0.0.1", unused_tcp_port, socket.AF_INET) started = time.monotonic() worker = Worker("1", [aserver]) assert worker._started is True await asyncio.sleep(35) worker.stop() assert worker._started is False assert worker.ping > started assert worker.ping_count == 2 aserver["sock"].close()
def test_stop(): with mock.patch('blackhole.worker.Worker.start') as mock_start, \ mock.patch('os.kill') as mock_kill: w = Worker([], []) w.chat_task = mock.Mock() w.heartbeat_task = mock.Mock() w.rtransport = mock.Mock() w.wtransport = mock.Mock() w.pid = 123 w.stop() assert mock_start.called is True assert mock_kill.called is True
async def test_restart(unused_tcp_port): aserver = server("127.0.0.1", unused_tcp_port, socket.AF_INET) started = time.monotonic() worker = Worker("1", [aserver]) assert worker._started is True await asyncio.sleep(25) worker.ping = time.monotonic() - 120 old_pid = worker.pid await asyncio.sleep(15) assert worker.pid is not old_pid worker.stop() assert worker._started is False assert worker.ping > started assert worker.ping_count == 0 aserver["sock"].close()
async def test_ping_pong(): aserver = server('127.0.0.1', 0, socket.AF_INET) worker = Worker('1', [aserver, ]) await asyncio.sleep(35) worker.stop() assert worker._started is False
async def test_start_stop(): worker = Worker(1, []) assert worker._started is True await asyncio.sleep(10) worker.stop() assert worker._started is False