def test_is_called_every_interval(self): clock = Clock() service = DHCPProbeService(sentinel.service, clock) # Avoid actually probing probe_dhcp = self.patch(service, "probe_dhcp") # Until the service has started, periodicprobe_dhcp() won't # be called. self.assertThat(probe_dhcp, MockNotCalled()) # The first call is issued at startup. service.startService() self.assertThat(probe_dhcp, MockCalledOnceWith()) # Wind clock forward one second less than the desired interval. clock.advance(service.check_interval - 1) # No more periodic calls made. self.assertEqual(1, len(get_mock_calls(probe_dhcp))) # Wind clock forward one second, past the interval. clock.advance(1) # Now there were two calls. self.assertThat(get_mock_calls(probe_dhcp), HasLength(2))
def test_is_called_every_interval(self): clock = Clock() service = ImageDownloadService(sentinel.service, sentinel.tftp_root, clock) # Avoid actual downloads: self.patch_download(service, None) maas_meta_last_modified = self.patch(tftppath, "maas_meta_last_modified") maas_meta_last_modified.return_value = None service.startService() # The first call is issued at startup. self.assertEqual(1, len(get_mock_calls(maas_meta_last_modified))) # Wind clock forward one second less than the desired interval. clock.advance(service.check_interval - 1) # No more periodic calls made. self.assertEqual(1, len(get_mock_calls(maas_meta_last_modified))) # Wind clock forward one second, past the interval. clock.advance(1) # Now there were two calls. self.assertEqual(2, len(get_mock_calls(maas_meta_last_modified))) # Forward another interval, should be three calls. clock.advance(service.check_interval) self.assertEqual(3, len(get_mock_calls(maas_meta_last_modified)))