Пример #1
0
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
Пример #2
0
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
Пример #3
0
def test_parent_start():
    with mock.patch('os.pipe', return_value=('', '')) as mock_pipe, \
        mock.patch('os.fork', return_value=123) as mock_fork, \
        mock.patch('os.close') as mock_close, \
        mock.patch('asyncio.ensure_future') as mock_async, \
            mock.patch('blackhole.worker.Worker.connect') as mock_connect:
        w = Worker([], [])
        w.pid = 123
    assert mock_pipe.call_count == 2
    assert mock_fork.called is True
    assert mock_close.call_count == 2
    assert mock_async.called is True
    assert mock_connect.called is True