def test_connect_cancels_existing_timeout_call(self): prober = ProberFactory(self.urls['200']) prober.timeoutCall = reactor.callLater(30, prober.failWithTimeoutError) old_timeout_call = prober.timeoutCall self.failUnless(old_timeout_call.active()) prober.connect() self.failIf(old_timeout_call.active()) self.failUnless(prober.timeoutCall.active()) return prober._deferred
def test_failure_cancel_timeout_call(self): prober = ProberFactory(self.urls['500']) deferred = prober.probe() self.failUnless(prober.timeoutCall.active()) def check_timeout_call(result): self.failIf(prober.timeoutCall.active()) return deferred.addErrback(check_timeout_call)
def test_success_cancel_timeout_call(self): prober = ProberFactory(self.urls['200']) deferred = prober.probe() self.assertTrue(prober.timeoutCall.active()) def check_timeout_call(result): self.assertFalse(prober.timeoutCall.active()) return deferred.addCallback(check_timeout_call)
def test_connect_cancels_existing_timeout_call(self): prober = ProberFactory(self.urls['200']) prober.timeoutCall = reactor.callLater( 30, prober.failWithTimeoutError) old_timeout_call = prober.timeoutCall self.failUnless(old_timeout_call.active()) prober.connect() self.failIf(old_timeout_call.active()) self.failUnless(prober.timeoutCall.active()) return prober._deferred
def test_environment_http_proxy_is_handled_correctly(self): os.environ['http_proxy'] = 'http://squid.internal:3128' prober = ProberFactory(self.urls['200']) self.failUnlessEqual(prober.request_host, 'localhost') self.failUnlessEqual(prober.request_port, self.port) self.failUnlessEqual(prober.request_path, '/valid-mirror') self.failUnlessEqual(prober.connect_host, 'squid.internal') self.failUnlessEqual(prober.connect_port, 3128) self.failUnlessEqual(prober.connect_path, self.urls['200'])
def _test_connect_to_host(self, url, host): """Check that a ProberFactory created with the given url will actually connect to the given host. """ prober = ProberFactory(url) def fakeConnect(host, port, factory): factory.connecting_to = host factory.succeeded('200') prober.connecting_to = None orig_connect = reactor.connectTCP reactor.connectTCP = fakeConnect def restore_connect(result, orig_connect): self.failUnlessEqual(prober.connecting_to, host) reactor.connectTCP = orig_connect return None deferred = prober.probe() return deferred.addCallback(restore_connect, orig_connect)
def test_config_no_http_proxy(self): prober = ProberFactory(self.urls['200']) self.assertThat( prober, MatchesStructure.byEquality(request_scheme='http', request_host='localhost', request_port=self.port, request_path='/valid-mirror', connect_scheme='http', connect_host='localhost', connect_port=self.port, connect_path='/valid-mirror'))
def test_config_http_proxy(self): self.pushConfig('launchpad', http_proxy='http://squid.internal:3128') prober = ProberFactory(self.urls['200']) self.assertThat( prober, MatchesStructure.byEquality(request_scheme='http', request_host='localhost', request_port=self.port, request_path='/valid-mirror', connect_scheme='http', connect_host='squid.internal', connect_port=3128, connect_path=self.urls['200']))
def _createProberStubConnectAndProbe(self, requests, timeouts): """Create a ProberFactory object with a URL inside self.host and call its probe() method. Before the prober.probe() method is called, we stub the connect method, because all we want is to check whether that method was called or not --we don't want to actually connect. """ def connect(): prober.connectCalled = True distributionmirror_prober.host_requests = {self.host: requests} distributionmirror_prober.host_timeouts = {self.host: timeouts} prober = ProberFactory('http://%s/baz' % self.host) prober.connectCalled = False prober.failed = lambda error: None prober.connect = connect prober.probe() return prober
def test_probe_sets_up_timeout_call(self): prober = ProberFactory(self.urls['200']) self.failUnless(getattr(prober, 'timeoutCall', None) is None) deferred = prober.probe() self.failUnless(getattr(prober, 'timeoutCall', None) is not None) return deferred
def _createProberAndProbe(self, url): prober = ProberFactory(url) return prober.probe()
def test_probe_sets_up_timeout_call(self): prober = ProberFactory(self.urls['200']) self.assertIsNone(getattr(prober, 'timeoutCall', None)) deferred = prober.probe() self.assertIsNotNone(getattr(prober, 'timeoutCall', None)) return deferred