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)
def test_future_gets_exception(container): pe = ParallelExecutor(container) def raises(): raise AssertionError() future = pe.submit(raises) with pytest.raises(AssertionError): future.result()
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()
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)
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
def test_stop_managed_container(container): container = container pe = ParallelExecutor(container) with pe as execution_context: execution_context.submit(everlasting_call) container.stop()
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)