コード例 #1
0
 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
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
    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)
コード例 #5
0
 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
コード例 #6
0
 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'])
コード例 #7
0
    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)
コード例 #8
0
    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)
コード例 #9
0
 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'))
コード例 #10
0
 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']))
コード例 #11
0
    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
コード例 #12
0
    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
コード例 #13
0
 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
コード例 #14
0
 def _createProberAndProbe(self, url):
     prober = ProberFactory(url)
     return prober.probe()
コード例 #15
0
 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
コード例 #16
0
 def _createProberAndProbe(self, url):
     prober = ProberFactory(url)
     return prober.probe()
コード例 #17
0
 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