]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
Set the HTTP connection timeout to 10s, and add a test for it.
authorCameron Dale <camrdale@gmail.com>
Fri, 9 May 2008 21:35:43 +0000 (14:35 -0700)
committerCameron Dale <camrdale@gmail.com>
Fri, 9 May 2008 21:35:43 +0000 (14:35 -0700)
apt_p2p/HTTPDownloader.py

index 1a0752c4e087a46a8bd562634d986c34a897576f..9e789b8485fa17e42e47ef371bdaf21115277a1b 100644 (file)
@@ -163,7 +163,7 @@ class Peer(ClientFactory):
         log.msg('Connecting to (%s, %d)' % (self.host, self.port))
         self.connecting = True
         d = protocol.ClientCreator(reactor, LoggingHTTPClientProtocol, self,
-                                   stats = self.stats, mirror = self.mirror).connectTCP(self.host, self.port)
+                                   stats = self.stats, mirror = self.mirror).connectTCP(self.host, self.port, timeout = 10)
         d.addCallbacks(self.connected, self.connectionError)
 
     def connected(self, proto):
@@ -576,6 +576,19 @@ class TestClientManager(unittest.TestCase):
         d.addCallback(self.gotResp, 1, 100)
         return d
         
+    def test_timeout(self):
+        """Tests a connection timeout."""
+        from twisted.internet.error import TimeoutError
+        host = 'steveholt.hopto.org'
+        self.client = Peer(host, 80)
+        self.timeout = 60
+        
+        d = self.client.get('/rfc/rfc0013.txt')
+        d.addCallback(self.gotResp, 1, 1070)
+        d = self.failUnlessFailure(d, TimeoutError)
+        d.addCallback(lambda a: self.flushLoggedErrors(TimeoutError))
+        return d
+        
     def tearDown(self):
         for p in self.pending_calls:
             if p.active():