Commits

Anonymous committed f4bfb95

add some teests. fix bad status line error (we retry)

  • Participants
  • Parent commits a45b826
  • Branches threadsafe

Comments (0)

Files changed (6)

 *.beam
 *.log
 restkit.egg-info
-
+dist/
 doc/_build/
 
 syntax: regexp

File restkit/httpc.py

             if proxy_auth:
                 headers['Proxy-Authorization'] = proxy_auth.strip()
             
-
         response, connection = self._request(uri, method, body, headers)
         resp = HTTPResponse(response)
         resp.final_url = self.final_url

File restkit/rest.py

 """
 
 import cgi
+import httplib
 import mimetypes
 import uuid
 import os
 import re
+import socket
 import StringIO
+import time
 import types
 import urllib
 
                     type_ = mimetypes.guess_type(body.name)[0]
                 _headers['Content-Type'] = type_ and type_ or 'application/octet-stream'
                 
-        try:
-            resp, data = self.transport.request(self.make_uri(uri, path, **params), 
-                method=method, body=body, headers=_headers, 
-                stream=_stream, stream_size=_stream_size)
-        except TransportError, e:
-            raise RequestError(str(e))
-
+                
+        def _try_request(retry=1):
+            try:
+                return self.transport.request(self.make_uri(uri, path, **params), 
+                            method=method, body=body, headers=_headers, 
+                            stream=_stream, stream_size=_stream_size)
+            except (socket.error, httplib.BadStatusLine), e:
+                if retry > 0:
+                    time.sleep(0.4)
+                return _try_request(retry-1)
+            except Exception, e:
+                RequestError(str(e))
+        
+        resp, data = _try_request()
         self.status  = status_code = resp.status
         self.response = resp
         

File tests/_server_test.py

 import cgi
 import os
 import socket
+import tempfile
 import threading
 import unittest
 import urlparse
 
     def __init__(self, request, client_address, server):
         self.auth = 'Basic ' + base64.encodestring('test:test')[:-1]
+        self.count = 0
         BaseHTTPRequestHandler.__init__(self, request, client_address, server)
         
+        
     def do_GET(self):
         self.parsed_uri = urlparse.urlparse(urllib.unquote(self.path))
         self.query = {}
             extra_headers = [('Content-type', 'text/plain'), 
                 ('Location', '/complete_redirect')]
             self._respond(301, extra_headers, "")
+            
         elif path == "/complete_redirect":
             extra_headers = [('Content-type', 'text/plain')]
             self._respond(200, extra_headers, "ok")
+        elif path == "/pool":
+            extra_headers = [('Content-type', 'text/plain')]
+            self._respond(200, extra_headers, "ok")
         else:
             self._respond(404, 
                 [('Content-type', 'text/plain')], "Not Found" )

File tests/eventlet_test.py

+# -*- coding: utf-8 -
+#
+# Copyright (c) 2008 (c) Benoit Chesneau <benoitc@e-engura.com> 
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
+import unittest
+from eventlet.util import wrap_threading_local_with_coro_local
+wrap_threading_local_with_coro_local()
+
+from restkit.rest import Resource
+from restkit.ext.eventlet_pool import ConnectionPool
+from _server_test import HOST, PORT, run_server_test
+
+from httpc_test import HTTPClientTestCase
+
+
+
+
+class EventletTestCase(HTTPClientTestCase):
+    def setUp(self):
+        
+        run_server_test()
+        self.url = 'http://%s:%s' % (HOST, PORT)
+        self.res = Resource(self.url, pool_class=ConnectionPool)
+
+if __name__ == '__main__':
+    from _server_test import run_server_test
+    run_server_test()
+    unittest.main()

File tests/httpc_test.py

 import os
 import socket
 import threading
+import Queue
 import unittest
 import urlparse
 
 from restkit import httpc
-from restkit.ext.eventlet_pool import ConnectionPool
+
 from restkit.rest import Resource, RestClient
 from restkit.errors import RequestFailed, ResourceNotFound, Unauthorized
 from _server_test import HOST, PORT, run_server_test
             result = res.get('/auth')
         self.assertRaises(Unauthorized, niettest)
         
- 
-class EventletTestCase(HTTPClientTestCase):
-    def setUp(self):
-        run_server_test()
-        self.url = 'http://%s:%s' % (HOST, PORT)
-        self.res = Resource(self.url, pool_class=ConnectionPool)
- 
- 
+
 if __name__ == '__main__':
     from _server_test import run_server_test
     run_server_test()