Fixed failing test by adding new makefile() method to GreenSSL.
This commit is contained in:
@@ -531,10 +531,30 @@ class GreenPipe(GreenFile):
|
|||||||
self.fd.fd.flush()
|
self.fd.fd.flush()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class RefCount(object):
|
||||||
|
""" Reference counting class only to be used with GreenSSL objects """
|
||||||
|
def __init__(self):
|
||||||
|
self._count = 1
|
||||||
|
|
||||||
|
def increment(self):
|
||||||
|
self._count += 1
|
||||||
|
|
||||||
|
def decrement(self):
|
||||||
|
self._count -= 1
|
||||||
|
assert self._count >= 0
|
||||||
|
|
||||||
|
def is_referenced(self):
|
||||||
|
return self._count > 0
|
||||||
|
|
||||||
|
|
||||||
class GreenSSL(GreenSocket):
|
class GreenSSL(GreenSocket):
|
||||||
def __init__(self, fd):
|
def __init__(self, fd, refcount = None):
|
||||||
GreenSocket.__init__(self, fd)
|
GreenSocket.__init__(self, fd)
|
||||||
self.sock = self
|
self.sock = self
|
||||||
|
self._refcount = refcount
|
||||||
|
if refcount is None:
|
||||||
|
self._refcount = RefCount()
|
||||||
|
|
||||||
read = read
|
read = read
|
||||||
|
|
||||||
@@ -550,7 +570,21 @@ class GreenSSL(GreenSocket):
|
|||||||
def issuer(self):
|
def issuer(self):
|
||||||
return self.fd.issuer()
|
return self.fd.issuer()
|
||||||
|
|
||||||
|
def dup(self):
|
||||||
|
raise NotImplemented("Dup not supported on SSL sockets")
|
||||||
|
|
||||||
|
def makefile(self, *args, **kw):
|
||||||
|
self._refcount.increment()
|
||||||
|
return GreenFile(type(self)(self.fd, refcount = self._refcount))
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self._refcount.decrement()
|
||||||
|
if self._refcount.is_referenced():
|
||||||
|
return
|
||||||
|
super(GreenSSL, self).close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def socketpair(*args):
|
def socketpair(*args):
|
||||||
one, two = socket.socketpair(*args)
|
one, two = socket.socketpair(*args)
|
||||||
|
@@ -586,6 +586,9 @@ class HttpSuite(object):
|
|||||||
def _get_response_body(self, params, connection):
|
def _get_response_body(self, params, connection):
|
||||||
if connection is None:
|
if connection is None:
|
||||||
connection = connect(params.url, params.use_proxy)
|
connection = connect(params.url, params.use_proxy)
|
||||||
|
# if we're creating a new connection we know the caller
|
||||||
|
# isn't going to reuse it
|
||||||
|
params.headers['connection'] = 'close'
|
||||||
connection.request(params.method, params.path, params.body,
|
connection.request(params.method, params.path, params.body,
|
||||||
params.headers)
|
params.headers)
|
||||||
params.response = connection.getresponse()
|
params.response = connection.getresponse()
|
||||||
|
@@ -267,9 +267,8 @@ class TestHttpd(tests.TestCase):
|
|||||||
|
|
||||||
def test_012_ssl_server(self):
|
def test_012_ssl_server(self):
|
||||||
from eventlet import httpc
|
from eventlet import httpc
|
||||||
def wsgi_app(self, environ, start_response):
|
def wsgi_app(environ, start_response):
|
||||||
print "wsgi_app"
|
start_response('200 OK', {})
|
||||||
print environ['wsgi.input']
|
|
||||||
return [environ['wsgi.input'].read()]
|
return [environ['wsgi.input'].read()]
|
||||||
|
|
||||||
certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt')
|
certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt')
|
||||||
@@ -279,10 +278,8 @@ class TestHttpd(tests.TestCase):
|
|||||||
|
|
||||||
api.spawn(wsgi.server, sock, wsgi_app)
|
api.spawn(wsgi.server, sock, wsgi_app)
|
||||||
|
|
||||||
print "pre request"
|
|
||||||
result = httpc.post("https://localhost:4201/foo", "abc")
|
result = httpc.post("https://localhost:4201/foo", "abc")
|
||||||
self.assertEquals(result, 'abc')
|
self.assertEquals(result, 'abc')
|
||||||
print "post request"
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Reference in New Issue
Block a user