[yum-commits] 2 commits - test/test_mirror.py urlgrabber/grabber.py

zpavlas at osuosl.org zpavlas at osuosl.org
Wed Dec 18 09:03:44 UTC 2013


 test/test_mirror.py   |   32 +++++++++++++++++++++++++++-----
 urlgrabber/grabber.py |    2 +-
 2 files changed, 28 insertions(+), 6 deletions(-)

New commits:
commit 3934ae4f52c7e785328db281299bbc78de4b93dd
Author: Zdenek Pavlas <zpavlas at redhat.com>
Date:   Mon Dec 16 12:40:31 2013 +0100

    Decrease the default_speed value. BZ 1043177

diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index f3fd02f..13f7919 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -999,7 +999,7 @@ class URLGrabberOptions:
         self.max_connections = 5
         self.timedhosts = None
         self.half_life = 30*24*60*60 # 30 days
-        self.default_speed = 1e6 # 1 MBit
+        self.default_speed = 500e3 # 500 kBps
         self.ftp_disable_epsv = False
         
     def __repr__(self):
commit b183419a2b36f7a8cc6df309a2ddf02927e0b605
Author: Zdenek Pavlas <zpavlas at redhat.com>
Date:   Wed Dec 18 09:48:28 2013 +0100

    tests: add a proper server shutdown to HttpReplyCode test

diff --git a/test/test_mirror.py b/test/test_mirror.py
index 6fdb668..4ce790c 100644
--- a/test/test_mirror.py
+++ b/test/test_mirror.py
@@ -268,33 +268,55 @@ class ActionTests(TestCase):
         self.assertEquals(self.g.calls, expected_calls)
         self.assertEquals(urlgrabber.mirror.DEBUG.logs, expected_logs)
                 
+import thread, socket
+LOCALPORT = 'localhost', 2000
 
 class HttpReplyCode(TestCase):
     def setUp(self):
+        # start the server
+        self.exit = False
         def server():
-            import socket
             s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-            s.bind(('localhost', 2000)); s.listen(1)
+            s.bind(LOCALPORT); s.listen(1)
             while 1:
                 c, a = s.accept()
+                if self.exit: c.close(); break
                 while not c.recv(4096).endswith('\r\n\r\n'): pass
                 c.sendall('HTTP/1.1 %d %s\r\n' % self.reply)
+                if self.content is not None:
+                    c.sendall('Content-Length: %d\r\n\r\n' % len(self.content))
+                    c.sendall(self.content)
                 c.close()
-        import thread
-        self.reply = 503, "Busy"
+            s.close()
+            self.exit = False
         thread.start_new_thread(server, ())
 
+        # create grabber and mirror group objects
         def failure(obj):
             self.code = getattr(obj.exception, 'code', None)
             return {}
         self.g  = URLGrabber()
-        self.mg = MirrorGroup(self.g, ['http://localhost:2000/'], failure_callback = failure)
+        self.mg = MirrorGroup(self.g, ['http://%s:%d' % LOCALPORT],
+                              failure_callback = failure)
+
+    def tearDown(self):
+        # shut down the server
+        self.exit = True
+        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        s.connect(LOCALPORT); s.close() # wake it up
+        while self.exit: pass # poor man's join
 
     def test_grab(self):
+        'tests the propagation of HTTP reply code'
+        self.reply = 503, "Busy"
+        self.content = None
+
+        # single
         self.assertRaises(URLGrabError, self.mg.urlgrab, 'foo')
         self.assertEquals(self.code, 503); del self.code
 
+        # multi
         err = []
         self.mg.urlgrab('foo', async = True, failfunc = err.append)
         urlgrabber.grabber.parallel_wait()


More information about the Yum-commits mailing list