def test_failure_on_construction_fails_as_expected(self, mock_service): ex = eager_tf_executor.EagerTFExecutor() ex_factory = executor_stacks.ResourceManagingExecutorFactory( lambda _: ex) with self.assertRaises(ValueError): with server_utils.server_context(ex_factory, 1, portpicker.pick_unused_port()): time.sleep(1)
def test_server_context_shuts_down_uncaught_exception( self, mock_logging_info): ex = eager_tf_executor.EagerTFExecutor() with self.assertRaises(TypeError): with server_utils.server_context( ex, 1, portpicker.pick_unused_port()) as server: time.sleep(1) raise TypeError mock_logging_info.assert_called_once_with('Shutting down server.')
def test_server_context_shuts_down_uncaught_exception( self, mock_logging_info): ex = eager_tf_executor.EagerTFExecutor() ex_factory = executor_stacks.ResourceManagingExecutorFactory( lambda _: ex) with self.assertRaises(TypeError): with server_utils.server_context( ex_factory, 1, portpicker.pick_unused_port()) as server: time.sleep(1) raise TypeError mock_logging_info.assert_called_once_with('Shutting down server.')
def test_server_context_shuts_down_under_keyboard_interrupt( self, mock_logging_info): ex = eager_tf_executor.EagerTFExecutor() with server_utils.server_context( ex, 1, portpicker.pick_unused_port()) as server: time.sleep(1) raise KeyboardInterrupt mock_logging_info.assert_has_calls([ mock.call('Server stopped by KeyboardInterrupt.'), mock.call('Shutting down server.') ])