def test__check_serial_doesnt_raise_error_on_successful_serial_match(self): service = RegionControllerService(sentinel.listener) result_serial = random.randint(1, 1000) formatted_serial = '{0:10d}'.format(result_serial) dns_names = [factory.make_name('domain') for _ in range(3)] # Mock pause so test runs faster. self.patch(region_controller, "pause").return_value = succeed(None) mock_lookup = self.patch(service.dnsResolver, "lookupAuthority") mock_lookup.side_effect = [ # First pass no results. succeed(([], [], [])), succeed(([], [], [])), succeed(([], [], [])), # First domain valid result. succeed(([self.make_soa_result(result_serial)], [], [])), succeed(([], [], [])), succeed(([], [], [])), # Second domain wrong serial. succeed(([self.make_soa_result(result_serial - 1)], [], [])), succeed(([], [], [])), # Third domain correct serial. succeed(([], [], [])), succeed(([self.make_soa_result(result_serial)], [], [])), # Second domain correct serial. succeed(([self.make_soa_result(result_serial)], [], [])), ] # Error should not be raised. return service._checkSerial((formatted_serial, dns_names))
def test__check_serial_handles_TimeoutError(self): service = RegionControllerService(sentinel.listener) result_serial = random.randint(1, 1000) formatted_serial = '{0:10d}'.format(result_serial) dns_names = [factory.make_name('domain') for _ in range(3)] # Mock pause so test runs faster. self.patch(region_controller, "pause").return_value = succeed(None) mock_lookup = self.patch(service.dnsResolver, "lookupAuthority") mock_lookup.side_effect = TimeoutError() # Error should not be raised. with ExpectedException(DNSReloadError): yield service._checkSerial((formatted_serial, dns_names))