def test_that_exceptions_from_shutdown_callbacks_are_ignored(self): another_callback = mock.Mock() self.application.runner_callbacks['shutdown'].append(another_callback) self.shutdown_callback.side_effect = Exception runner = sprockets.http.runner.Runner(self.application) runner.run(8080) runner._shutdown() self.shutdown_callback.assert_called_once_with(self.application) another_callback.assert_called_once_with(self.application)
def test_that_shutdown_waits_for_timeouts(self): def add_timeout(_, callback): self.io_loop._timeouts.pop() callback() self.io_loop.add_timeout = mock.Mock(side_effect=add_timeout) self.io_loop._timeouts = [mock.Mock(), mock.Mock()] runner = sprockets.http.runner.Runner(self.application) runner.run(8000) runner._shutdown() self.io_loop.stop.assert_called_once_with() self.assertEqual(self.io_loop.add_timeout.call_count, 2)
def test_that_shutdown_stops_after_timelimit(self): def add_timeout(_, callback): time.sleep(0.1) callback() self.io_loop.add_timeout = mock.Mock(side_effect=add_timeout) self.io_loop._timeouts = [mock.Mock()] runner = sprockets.http.runner.Runner(self.application) runner.shutdown_limit = 0.25 runner.run(8000) runner._shutdown() self.io_loop.stop.assert_called_once_with() self.assertNotEqual(self.io_loop._timeouts, [])
def on_started(*args, **kwargs): with mock.patch('sprockets.http.runner.Runner.stop_server'): runner._shutdown()
def test_that_shutdown_callback_invoked(self): runner = sprockets.http.runner.Runner(self.application) runner.run(8080) runner._shutdown() self.shutdown_callback.assert_called_once_with(self.application)