Exemple #1
0
    def test_monitorServices_calls_ensureServices(self):
        # Pretend we're in a production environment.
        self.patch(service_monitor_service,
                   "is_dev_environment").return_value = False

        monitor_service = ServiceMonitorService(Clock())
        mock_ensureServices = self.patch(service_monitor, "ensureServices")
        monitor_service.monitorServices()
        self.assertThat(mock_ensureServices, MockCalledOnceWith())
    def test_monitorServices_does_not_do_anything_in_dev_environment(self):
        # Belt-n-braces make sure we're in a development environment.
        self.assertTrue(service_monitor_service.is_dev_environment())

        monitor_service = ServiceMonitorService(Clock())
        mock_ensureServices = self.patch(service_monitor, "ensureServices")
        with TwistedLoggerFixture() as logger:
            monitor_service.monitorServices()
        self.assertThat(mock_ensureServices, MockNotCalled())
        self.assertDocTestMatches(
            "Skipping check of services; they're not running under the "
            "supervision of systemd.", logger.output)
    def test_monitorServices_handles_failure(self):
        # Pretend we're in a production environment.
        self.patch(
            service_monitor_service, "is_dev_environment").return_value = False

        monitor_service = ServiceMonitorService(Clock())
        mock_ensureServices = self.patch(service_monitor, "ensureServices")
        mock_ensureServices.return_value = fail(factory.make_exception())
        with TwistedLoggerFixture() as logger:
            monitor_service.monitorServices()
        self.assertDocTestMatches("""\
            Failed to monitor services and update database.
            Traceback (most recent call last):
            ...""", logger.output)