示例#1
0
def test_no_submit_after_shutdown(container):
    pe = ParallelExecutor(container)
    to_call = Mock()
    with pe as execution_context:
        execution_context.submit(to_call, 1)
    with pytest.raises(RuntimeError):
        pe.submit(to_call, 2)
示例#2
0
def test_no_submit_after_shutdown(container):
    pe = ParallelExecutor(container)
    to_call = Mock()
    with pe as execution_context:
        execution_context.submit(to_call, 1)
    with pytest.raises(RuntimeError):
        pe.submit(to_call, 2)
示例#3
0
def test_future_gets_exception(container):
    pe = ParallelExecutor(container)

    def raises():
        raise AssertionError()

    future = pe.submit(raises)

    with pytest.raises(AssertionError):
        future.result()
示例#4
0
def test_future_gets_exception(container):
    pe = ParallelExecutor(container)

    def raises():
        raise AssertionError()

    future = pe.submit(raises)

    with pytest.raises(AssertionError):
        future.result()
示例#5
0
def test_kill_managed_container(container):
    container = container
    pe = ParallelExecutor(container)
    with pe as execution_context:
        f = execution_context.submit(everlasting_call)
        container.kill()
        with pytest.raises(GreenletExit):
            f.result()
示例#6
0
def test_calling_result_waits(container):
    to_call = Mock(return_value=99)
    future = ParallelExecutor(container).submit(to_call, 1)
    assert future.result() == 99
    to_call.assert_called_with(1)
示例#7
0
def test_parallel_executor_submit_makes_call(container):
    to_call = Mock(return_value=99)
    future = ParallelExecutor(container).submit(to_call, 1)
    with wait_for_call(5, to_call) as to_call_waited:
        to_call_waited.assert_called_with(1)
        assert future.result() == 99
示例#8
0
def test_stop_managed_container(container):
    container = container
    pe = ParallelExecutor(container)
    with pe as execution_context:
        execution_context.submit(everlasting_call)
        container.stop()
示例#9
0
def test_parallel_executor_context_manager(container):
    to_call = Mock()
    with ParallelExecutor(container) as execution_context:
        execution_context.submit(to_call, 4)
    # No waiting, the context manager handles that
    to_call.assert_called_with(4)
示例#10
0
def test_calling_result_waits(container):
    to_call = Mock(return_value=99)
    future = ParallelExecutor(container).submit(to_call, 1)
    assert future.result() == 99
    to_call.assert_called_with(1)
示例#11
0
def test_parallel_executor_submit_makes_call(container):
    to_call = Mock(return_value=99)
    future = ParallelExecutor(container).submit(to_call, 1)
    with wait_for_call(5, to_call) as to_call_waited:
        to_call_waited.assert_called_with(1)
        assert future.result() == 99