def test_init_with_default_interval(self):
        # The service itself calls `check_status` in a thread, via a couple of
        # decorators. This indirection makes it clearer to mock
        # `cleanup_old_nonces` here and track calls to it.
        mock_check_status = self.patch(status_monitor, "check_status")
        # Making `deferToDatabase` use the current thread helps testing.
        self.patch(status_monitor, "deferToDatabase", maybeDeferred)

        service = StatusMonitorService()
        # Use a deterministic clock instead of the reactor for testing.
        service.clock = Clock()

        # The interval is stored as `step` by TimerService,
        # StatusMonitorService's parent class.
        interval = 60  # seconds.
        self.assertEqual(service.step, interval)

        # `check_status` is not called before the service is started.
        self.assertThat(mock_check_status, MockNotCalled())
        # `check_status` is called the moment the service is started.
        service.startService()
        self.assertThat(mock_check_status, MockCalledOnceWith())
        # Advancing the clock by `interval - 1` means that
        # `mark_nodes_failed_after_expiring` has still only been called once.
        service.clock.advance(interval - 1)
        self.assertThat(mock_check_status, MockCalledOnceWith())
        # Advancing the clock one more second causes another call to
        # `check_status`.
        service.clock.advance(1)
        self.assertThat(mock_check_status, MockCallsMatch(call(), call()))
 def test_interval_can_be_set(self):
     interval = self.getUniqueInteger()
     service = StatusMonitorService(interval)
     self.assertEqual(interval, service.step)