Example #1
0
def test_stop():
    cfile = create_config(('listen=:9999, :::9999', 'workers=2', ))
    Config(cfile).load()
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    with mock.patch('socket.socket.bind'), \
            mock.patch('blackhole.worker.Worker.start'):
        supervisor = Supervisor(loop)
        supervisor.start_workers()
        assert len(supervisor.workers) == 2
        with mock.patch('blackhole.worker.Worker.stop') as mock_stop, \
                pytest.raises(SystemExit) as err:
            supervisor.stop()
    assert mock_stop.call_count == 2
    assert str(err.value) == '0'
    supervisor.loop.stop()
Example #2
0
def test_stop():
    cfile = create_config(("listen=:9999, :::9999", "workers=2"))
    Config(cfile).load()
    loop = asyncio.new_event_loop()
    with mock.patch("socket.socket.bind"), mock.patch(
        "blackhole.worker.Worker.start"
    ):
        supervisor = Supervisor(loop=loop)
        supervisor.start_workers()
        assert len(supervisor.workers) == 2
        with mock.patch(
            "blackhole.worker.Worker.stop"
        ) as mock_stop, pytest.raises(SystemExit) as exc:
            supervisor.stop()
    assert mock_stop.call_count == 2
    assert exc.value.code == 0
    loop.run_until_complete(loop.shutdown_asyncgens())
    loop.close()