tweaks to remove some DeprecationWarnings when running tests
This commit is contained in:
@@ -8,11 +8,13 @@ try:
|
|||||||
from eventlet import timeout
|
from eventlet import timeout
|
||||||
from eventlet import patcher
|
from eventlet import patcher
|
||||||
from eventlet import greenio
|
from eventlet import greenio
|
||||||
|
import greenlet
|
||||||
|
|
||||||
sleep = greenthread.sleep
|
sleep = greenthread.sleep
|
||||||
spawn = greenthread.spawn
|
spawn = greenthread.spawn
|
||||||
spawn_n = greenthread.spawn_n
|
spawn_n = greenthread.spawn_n
|
||||||
spawn_after = greenthread.spawn_after
|
spawn_after = greenthread.spawn_after
|
||||||
|
kill = greenthread.kill
|
||||||
|
|
||||||
Timeout = timeout.Timeout
|
Timeout = timeout.Timeout
|
||||||
with_timeout = timeout.with_timeout
|
with_timeout = timeout.with_timeout
|
||||||
@@ -28,6 +30,8 @@ try:
|
|||||||
connect = greenio.connect
|
connect = greenio.connect
|
||||||
listen = greenio.listen
|
listen = greenio.listen
|
||||||
|
|
||||||
|
getcurrent = greenlet.getcurrent
|
||||||
|
|
||||||
# deprecated
|
# deprecated
|
||||||
TimeoutError = timeout.Timeout
|
TimeoutError = timeout.Timeout
|
||||||
exc_after = greenthread.exc_after
|
exc_after = greenthread.exc_after
|
||||||
|
@@ -10,6 +10,7 @@ from eventlet.support import greenlets as greenlet
|
|||||||
from eventlet import hubs
|
from eventlet import hubs
|
||||||
from eventlet import greenthread
|
from eventlet import greenthread
|
||||||
from eventlet import debug
|
from eventlet import debug
|
||||||
|
from eventlet import Timeout
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'call_after', 'exc_after', 'getcurrent', 'get_default_hub', 'get_hub',
|
'call_after', 'exc_after', 'getcurrent', 'get_default_hub', 'get_hub',
|
||||||
@@ -68,8 +69,11 @@ def ssl_listener(address, certificate, private_key):
|
|||||||
accept a connection on the newly bound socket.
|
accept a connection on the newly bound socket.
|
||||||
"""
|
"""
|
||||||
from eventlet import util
|
from eventlet import util
|
||||||
socket = util.wrap_ssl(util.tcp_socket(), certificate, private_key, True)
|
import socket
|
||||||
util.socket_bind_and_listen(socket, address)
|
|
||||||
|
socket = util.wrap_ssl(socket.socket(), certificate, private_key, True)
|
||||||
|
socket.bind(address)
|
||||||
|
socket.listen(50)
|
||||||
return socket
|
return socket
|
||||||
|
|
||||||
def connect_tcp(address, localaddr=None):
|
def connect_tcp(address, localaddr=None):
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import traceback
|
import traceback
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from eventlet import api
|
import eventlet
|
||||||
from eventlet import event as _event
|
from eventlet import event as _event
|
||||||
from eventlet import hubs
|
from eventlet import hubs
|
||||||
from eventlet import greenthread
|
from eventlet import greenthread
|
||||||
@@ -62,8 +62,8 @@ class metaphore(object):
|
|||||||
... print "%s decrementing" % id
|
... print "%s decrementing" % id
|
||||||
... count.dec()
|
... count.dec()
|
||||||
...
|
...
|
||||||
>>> _ = api.spawn(decrementer, count, 'A')
|
>>> _ = eventlet.spawn(decrementer, count, 'A')
|
||||||
>>> _ = api.spawn(decrementer, count, 'B')
|
>>> _ = eventlet.spawn(decrementer, count, 'B')
|
||||||
>>> count.inc(2)
|
>>> count.inc(2)
|
||||||
>>> count.wait()
|
>>> count.wait()
|
||||||
A decrementing
|
A decrementing
|
||||||
@@ -174,17 +174,17 @@ class Queue(object):
|
|||||||
if exc is None:
|
if exc is None:
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
api.getcurrent().throw(*exc)
|
eventlet.getcurrent().throw(*exc)
|
||||||
else:
|
else:
|
||||||
self._waiters.add(api.getcurrent())
|
self._waiters.add(eventlet.getcurrent())
|
||||||
try:
|
try:
|
||||||
result, exc = hubs.get_hub().switch()
|
result, exc = hubs.get_hub().switch()
|
||||||
if exc is None:
|
if exc is None:
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
api.getcurrent().throw(*exc)
|
eventlet.getcurrent().throw(*exc)
|
||||||
finally:
|
finally:
|
||||||
self._waiters.discard(api.getcurrent())
|
self._waiters.discard(eventlet.getcurrent())
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
return len(self.items) > 0
|
return len(self.items) > 0
|
||||||
@@ -227,7 +227,7 @@ class Channel(object):
|
|||||||
def send(self, result=None, exc=None):
|
def send(self, result=None, exc=None):
|
||||||
if exc is not None and not isinstance(exc, tuple):
|
if exc is not None and not isinstance(exc, tuple):
|
||||||
exc = (exc, )
|
exc = (exc, )
|
||||||
if api.getcurrent() is hubs.get_hub().greenlet:
|
if eventlet.getcurrent() is hubs.get_hub().greenlet:
|
||||||
self.items.append((result, exc))
|
self.items.append((result, exc))
|
||||||
if self._waiters:
|
if self._waiters:
|
||||||
hubs.get_hub().schedule_call_global(0, self._do_switch)
|
hubs.get_hub().schedule_call_global(0, self._do_switch)
|
||||||
@@ -238,11 +238,11 @@ class Channel(object):
|
|||||||
if self._waiters:
|
if self._waiters:
|
||||||
hubs.get_hub().schedule_call_global(0, self._do_switch)
|
hubs.get_hub().schedule_call_global(0, self._do_switch)
|
||||||
if len(self.items) > self.max_size:
|
if len(self.items) > self.max_size:
|
||||||
self._senders.add(api.getcurrent())
|
self._senders.add(eventlet.getcurrent())
|
||||||
try:
|
try:
|
||||||
hubs.get_hub().switch()
|
hubs.get_hub().switch()
|
||||||
finally:
|
finally:
|
||||||
self._senders.discard(api.getcurrent())
|
self._senders.discard(eventlet.getcurrent())
|
||||||
|
|
||||||
def send_exception(self, *args):
|
def send_exception(self, *args):
|
||||||
# the arguments are the same as for greenlet.throw
|
# the arguments are the same as for greenlet.throw
|
||||||
@@ -274,19 +274,19 @@ class Channel(object):
|
|||||||
if exc is None:
|
if exc is None:
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
api.getcurrent().throw(*exc)
|
eventlet.getcurrent().throw(*exc)
|
||||||
else:
|
else:
|
||||||
if self._senders:
|
if self._senders:
|
||||||
hubs.get_hub().schedule_call_global(0, self._do_switch)
|
hubs.get_hub().schedule_call_global(0, self._do_switch)
|
||||||
self._waiters.add(api.getcurrent())
|
self._waiters.add(eventlet.getcurrent())
|
||||||
try:
|
try:
|
||||||
result, exc = hubs.get_hub().switch()
|
result, exc = hubs.get_hub().switch()
|
||||||
if exc is None:
|
if exc is None:
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
api.getcurrent().throw(*exc)
|
eventlet.getcurrent().throw(*exc)
|
||||||
finally:
|
finally:
|
||||||
self._waiters.discard(api.getcurrent())
|
self._waiters.discard(eventlet.getcurrent())
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
return len(self.items) > 0
|
return len(self.items) > 0
|
||||||
@@ -332,7 +332,7 @@ class Actor(object):
|
|||||||
|
|
||||||
self._mailbox = collections.deque()
|
self._mailbox = collections.deque()
|
||||||
self._event = _event.Event()
|
self._event = _event.Event()
|
||||||
self._killer = api.spawn(self.run_forever)
|
self._killer = eventlet.spawn(self.run_forever)
|
||||||
from eventlet import greenpool
|
from eventlet import greenpool
|
||||||
self._pool = greenpool.GreenPool(concurrency)
|
self._pool = greenpool.GreenPool(concurrency)
|
||||||
|
|
||||||
@@ -394,7 +394,7 @@ class Actor(object):
|
|||||||
received message 2
|
received message 2
|
||||||
received message 3
|
received message 3
|
||||||
|
|
||||||
>>> api.kill(a._killer) # test cleanup
|
>>> eventlet.kill(a._killer) # test cleanup
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ def g_log(*args):
|
|||||||
|
|
||||||
__original_socket__ = socket.socket
|
__original_socket__ = socket.socket
|
||||||
def tcp_socket():
|
def tcp_socket():
|
||||||
warnings.warn("eventlet.util.tcp_sockt is deprecated."
|
warnings.warn("eventlet.util.tcp_socket is deprecated."
|
||||||
"Please use the standard socket technique for this instead:"
|
"Please use the standard socket technique for this instead:"
|
||||||
"sock = socket.socket()",
|
"sock = socket.socket()",
|
||||||
DeprecationWarning, stacklevel=2)
|
DeprecationWarning, stacklevel=2)
|
||||||
|
@@ -2,7 +2,6 @@ import sys
|
|||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
from eventlet import debug
|
from eventlet import debug
|
||||||
from eventlet import api
|
|
||||||
from tests import LimitedTestCase, main
|
from tests import LimitedTestCase, main
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
@@ -103,8 +102,8 @@ class TestDebug(LimitedTestCase):
|
|||||||
|
|
||||||
def test_hub_exceptions(self):
|
def test_hub_exceptions(self):
|
||||||
debug.hub_exceptions(True)
|
debug.hub_exceptions(True)
|
||||||
server = api.tcp_listener(('0.0.0.0', 0))
|
server = eventlet.listen(('0.0.0.0', 0))
|
||||||
client = api.connect_tcp(('127.0.0.1', server.getsockname()[1]))
|
client = eventlet.connect(('127.0.0.1', server.getsockname()[1]))
|
||||||
client_2, addr = server.accept()
|
client_2, addr = server.accept()
|
||||||
|
|
||||||
def hurl(s):
|
def hurl(s):
|
||||||
|
@@ -1,12 +1,22 @@
|
|||||||
from tests import skipped, LimitedTestCase, skip_unless
|
from tests import skipped, LimitedTestCase, skip_unless
|
||||||
from unittest import main
|
from unittest import main
|
||||||
from eventlet import api, util, coros, greenio
|
import eventlet
|
||||||
|
from eventlet import util, coros, greenio
|
||||||
import socket
|
import socket
|
||||||
import os
|
import os
|
||||||
|
|
||||||
certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt')
|
certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt')
|
||||||
private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key')
|
private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key')
|
||||||
|
|
||||||
|
def listen_ssl_socket(address=('127.0.0.1', 0)):
|
||||||
|
sock = util.wrap_ssl(socket.socket(), certificate_file,
|
||||||
|
private_key_file, True)
|
||||||
|
sock.bind(address)
|
||||||
|
sock.listen(50)
|
||||||
|
|
||||||
|
return sock
|
||||||
|
|
||||||
|
|
||||||
class SSLTest(LimitedTestCase):
|
class SSLTest(LimitedTestCase):
|
||||||
def test_duplex_response(self):
|
def test_duplex_response(self):
|
||||||
def serve(listener):
|
def serve(listener):
|
||||||
@@ -14,10 +24,11 @@ class SSLTest(LimitedTestCase):
|
|||||||
stuff = sock.read(8192)
|
stuff = sock.read(8192)
|
||||||
sock.write('response')
|
sock.write('response')
|
||||||
|
|
||||||
sock = api.ssl_listener(('127.0.0.1', 0), certificate_file, private_key_file)
|
sock = listen_ssl_socket()
|
||||||
server_coro = coros.execute(serve, sock)
|
|
||||||
|
|
||||||
client = util.wrap_ssl(api.connect_tcp(('127.0.0.1', sock.getsockname()[1])))
|
server_coro = eventlet.spawn(serve, sock)
|
||||||
|
|
||||||
|
client = util.wrap_ssl(eventlet.connect(('127.0.0.1', sock.getsockname()[1])))
|
||||||
client.write('line 1\r\nline 2\r\n\r\n')
|
client.write('line 1\r\nline 2\r\n\r\n')
|
||||||
self.assertEquals(client.read(8192), 'response')
|
self.assertEquals(client.read(8192), 'response')
|
||||||
server_coro.wait()
|
server_coro.wait()
|
||||||
@@ -31,10 +42,11 @@ class SSLTest(LimitedTestCase):
|
|||||||
except greenio.SSL.ZeroReturnError:
|
except greenio.SSL.ZeroReturnError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
sock = api.ssl_listener(('127.0.0.1', 0), certificate_file, private_key_file)
|
sock = listen_ssl_socket()
|
||||||
server_coro = coros.execute(serve, sock)
|
|
||||||
|
|
||||||
raw_client = api.connect_tcp(('127.0.0.1', sock.getsockname()[1]))
|
server_coro = eventlet.spawn(serve, sock)
|
||||||
|
|
||||||
|
raw_client = eventlet.connect(('127.0.0.1', sock.getsockname()[1]))
|
||||||
client = util.wrap_ssl(raw_client)
|
client = util.wrap_ssl(raw_client)
|
||||||
client.write('X')
|
client.write('X')
|
||||||
greenio.shutdown_safe(client)
|
greenio.shutdown_safe(client)
|
||||||
@@ -45,8 +57,8 @@ class SSLTest(LimitedTestCase):
|
|||||||
def serve(listener):
|
def serve(listener):
|
||||||
sock, addr = listener.accept()
|
sock, addr = listener.accept()
|
||||||
stuff = sock.read(8192)
|
stuff = sock.read(8192)
|
||||||
sock = api.ssl_listener(('127.0.0.1', 0), certificate_file, private_key_file)
|
sock = listen_ssl_socket()
|
||||||
server_coro = coros.execute(serve, sock)
|
server_coro = eventlet.spawn(serve, sock)
|
||||||
|
|
||||||
raw_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
raw_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
ssl_client = util.wrap_ssl(raw_client)
|
ssl_client = util.wrap_ssl(raw_client)
|
||||||
@@ -71,12 +83,10 @@ class SocketSSLTest(LimitedTestCase):
|
|||||||
sock.write('content')
|
sock.write('content')
|
||||||
greenio.shutdown_safe(sock)
|
greenio.shutdown_safe(sock)
|
||||||
sock.close()
|
sock.close()
|
||||||
listener = api.ssl_listener(('', 0),
|
listener = listen_ssl_socket(('', 0))
|
||||||
certificate_file,
|
killer = eventlet.spawn(serve, listener)
|
||||||
private_key_file)
|
|
||||||
killer = api.spawn(serve, listener)
|
|
||||||
from eventlet.green.socket import ssl
|
from eventlet.green.socket import ssl
|
||||||
client = ssl(api.connect_tcp(('localhost', listener.getsockname()[1])))
|
client = ssl(eventlet.connect(('localhost', listener.getsockname()[1])))
|
||||||
self.assertEquals(client.read(1024), 'content')
|
self.assertEquals(client.read(1024), 'content')
|
||||||
self.assertEquals(client.read(1024), '')
|
self.assertEquals(client.read(1024), '')
|
||||||
|
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
|
import eventlet
|
||||||
from eventlet import pool, coros, api, hubs, timeout
|
from eventlet import pool, coros, api, hubs, timeout
|
||||||
|
from eventlet import event as _event
|
||||||
from tests import LimitedTestCase
|
from tests import LimitedTestCase
|
||||||
from unittest import main
|
from unittest import main
|
||||||
|
|
||||||
@@ -6,7 +8,7 @@ class TestCoroutinePool(LimitedTestCase):
|
|||||||
klass = pool.Pool
|
klass = pool.Pool
|
||||||
|
|
||||||
def test_execute_async(self):
|
def test_execute_async(self):
|
||||||
done = coros.Event()
|
done = _event.Event()
|
||||||
def some_work():
|
def some_work():
|
||||||
done.send()
|
done.send()
|
||||||
pool = self.klass(0, 2)
|
pool = self.klass(0, 2)
|
||||||
@@ -23,7 +25,7 @@ class TestCoroutinePool(LimitedTestCase):
|
|||||||
|
|
||||||
def test_waiting(self):
|
def test_waiting(self):
|
||||||
pool = self.klass(0,1)
|
pool = self.klass(0,1)
|
||||||
done = coros.Event()
|
done = _event.Event()
|
||||||
def consume():
|
def consume():
|
||||||
done.wait()
|
done.wait()
|
||||||
def waiter(pool):
|
def waiter(pool):
|
||||||
@@ -31,13 +33,13 @@ class TestCoroutinePool(LimitedTestCase):
|
|||||||
evt.wait()
|
evt.wait()
|
||||||
|
|
||||||
waiters = []
|
waiters = []
|
||||||
waiters.append(coros.execute(waiter, pool))
|
waiters.append(eventlet.spawn(waiter, pool))
|
||||||
api.sleep(0)
|
api.sleep(0)
|
||||||
self.assertEqual(pool.waiting(), 0)
|
self.assertEqual(pool.waiting(), 0)
|
||||||
waiters.append(coros.execute(waiter, pool))
|
waiters.append(eventlet.spawn(waiter, pool))
|
||||||
api.sleep(0)
|
api.sleep(0)
|
||||||
self.assertEqual(pool.waiting(), 1)
|
self.assertEqual(pool.waiting(), 1)
|
||||||
waiters.append(coros.execute(waiter, pool))
|
waiters.append(eventlet.spawn(waiter, pool))
|
||||||
api.sleep(0)
|
api.sleep(0)
|
||||||
self.assertEqual(pool.waiting(), 2)
|
self.assertEqual(pool.waiting(), 2)
|
||||||
done.send(None)
|
done.send(None)
|
||||||
@@ -46,7 +48,7 @@ class TestCoroutinePool(LimitedTestCase):
|
|||||||
self.assertEqual(pool.waiting(), 0)
|
self.assertEqual(pool.waiting(), 0)
|
||||||
|
|
||||||
def test_multiple_coros(self):
|
def test_multiple_coros(self):
|
||||||
evt = coros.Event()
|
evt = _event.Event()
|
||||||
results = []
|
results = []
|
||||||
def producer():
|
def producer():
|
||||||
results.append('prod')
|
results.append('prod')
|
||||||
@@ -86,7 +88,7 @@ class TestCoroutinePool(LimitedTestCase):
|
|||||||
outer_waiter = pool.execute(reenter)
|
outer_waiter = pool.execute(reenter)
|
||||||
outer_waiter.wait()
|
outer_waiter.wait()
|
||||||
|
|
||||||
evt = coros.Event()
|
evt = _event.Event()
|
||||||
def reenter_async():
|
def reenter_async():
|
||||||
pool.execute_async(lambda a: a, 'reenter')
|
pool.execute_async(lambda a: a, 'reenter')
|
||||||
evt.send('done')
|
evt.send('done')
|
||||||
@@ -97,9 +99,9 @@ class TestCoroutinePool(LimitedTestCase):
|
|||||||
def assert_pool_has_free(self, pool, num_free):
|
def assert_pool_has_free(self, pool, num_free):
|
||||||
def wait_long_time(e):
|
def wait_long_time(e):
|
||||||
e.wait()
|
e.wait()
|
||||||
timer = api.exc_after(1, api.TimeoutError)
|
timer = timeout.Timeout(1, api.TimeoutError)
|
||||||
try:
|
try:
|
||||||
evt = coros.Event()
|
evt = _event.Event()
|
||||||
for x in xrange(num_free):
|
for x in xrange(num_free):
|
||||||
pool.execute(wait_long_time, evt)
|
pool.execute(wait_long_time, evt)
|
||||||
# if the pool has fewer free than we expect,
|
# if the pool has fewer free than we expect,
|
||||||
@@ -109,7 +111,7 @@ class TestCoroutinePool(LimitedTestCase):
|
|||||||
|
|
||||||
# if the runtime error is not raised it means the pool had
|
# if the runtime error is not raised it means the pool had
|
||||||
# some unexpected free items
|
# some unexpected free items
|
||||||
timer = api.exc_after(0, RuntimeError)
|
timer = timeout.Timeout(0, RuntimeError)
|
||||||
self.assertRaises(RuntimeError, pool.execute, wait_long_time, evt)
|
self.assertRaises(RuntimeError, pool.execute, wait_long_time, evt)
|
||||||
|
|
||||||
# clean up by causing all the wait_long_time functions to return
|
# clean up by causing all the wait_long_time functions to return
|
||||||
@@ -119,7 +121,7 @@ class TestCoroutinePool(LimitedTestCase):
|
|||||||
|
|
||||||
def test_resize(self):
|
def test_resize(self):
|
||||||
pool = self.klass(max_size=2)
|
pool = self.klass(max_size=2)
|
||||||
evt = coros.Event()
|
evt = _event.Event()
|
||||||
def wait_long_time(e):
|
def wait_long_time(e):
|
||||||
e.wait()
|
e.wait()
|
||||||
pool.execute(wait_long_time, evt)
|
pool.execute(wait_long_time, evt)
|
||||||
@@ -203,7 +205,7 @@ class TestCoroutinePool(LimitedTestCase):
|
|||||||
tp = pools.TokenPool(max_size=1)
|
tp = pools.TokenPool(max_size=1)
|
||||||
token = tp.get() # empty pool
|
token = tp.get() # empty pool
|
||||||
def do_receive(tp):
|
def do_receive(tp):
|
||||||
api.exc_after(0, RuntimeError())
|
timeout.Timeout(0, RuntimeError())
|
||||||
try:
|
try:
|
||||||
t = tp.get()
|
t = tp.get()
|
||||||
self.fail("Shouldn't have recieved anything from the pool")
|
self.fail("Shouldn't have recieved anything from the pool")
|
||||||
|
@@ -2,6 +2,7 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
from eventlet.api import sleep, with_timeout
|
from eventlet.api import sleep, with_timeout
|
||||||
from eventlet import api, proc, coros
|
from eventlet import api, proc, coros
|
||||||
|
from eventlet import event as _event
|
||||||
from tests import LimitedTestCase, skipped
|
from tests import LimitedTestCase, skipped
|
||||||
|
|
||||||
DELAY = 0.01
|
DELAY = 0.01
|
||||||
@@ -61,12 +62,12 @@ class TestProc(LimitedTestCase):
|
|||||||
|
|
||||||
def test_event(self):
|
def test_event(self):
|
||||||
p = proc.spawn(lambda : 100)
|
p = proc.spawn(lambda : 100)
|
||||||
event = coros.Event()
|
event = _event.Event()
|
||||||
p.link(event)
|
p.link(event)
|
||||||
self.assertEqual(event.wait(), 100)
|
self.assertEqual(event.wait(), 100)
|
||||||
|
|
||||||
for i in xrange(3):
|
for i in xrange(3):
|
||||||
event2 = coros.Event()
|
event2 = _event.Event()
|
||||||
p.link(event2)
|
p.link(event2)
|
||||||
self.assertEqual(event2.wait(), 100)
|
self.assertEqual(event2.wait(), 100)
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ class TestCase(LimitedTestCase):
|
|||||||
self.p.unlink()
|
self.p.unlink()
|
||||||
|
|
||||||
def set_links(self, p, first_time, kill_exc_type):
|
def set_links(self, p, first_time, kill_exc_type):
|
||||||
event = coros.Event()
|
event = _event.Event()
|
||||||
self.link(p, event)
|
self.link(p, event)
|
||||||
|
|
||||||
proc_flag = []
|
proc_flag = []
|
||||||
@@ -111,13 +112,13 @@ class TestCase(LimitedTestCase):
|
|||||||
self.link(p, lambda *args: callback_flag.remove('initial'))
|
self.link(p, lambda *args: callback_flag.remove('initial'))
|
||||||
|
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
self.link(p, coros.Event())
|
self.link(p, _event.Event())
|
||||||
self.link(p, coros.queue(1))
|
self.link(p, coros.queue(1))
|
||||||
return event, receiver, proc_flag, queue, callback_flag
|
return event, receiver, proc_flag, queue, callback_flag
|
||||||
|
|
||||||
def set_links_timeout(self, link):
|
def set_links_timeout(self, link):
|
||||||
# stuff that won't be touched
|
# stuff that won't be touched
|
||||||
event = coros.Event()
|
event = _event.Event()
|
||||||
link(event)
|
link(event)
|
||||||
|
|
||||||
proc_finished_flag = []
|
proc_finished_flag = []
|
||||||
@@ -259,11 +260,11 @@ class TestStuff(LimitedTestCase):
|
|||||||
y = proc.spawn(lambda : 2)
|
y = proc.spawn(lambda : 2)
|
||||||
z = proc.spawn(lambda : 3)
|
z = proc.spawn(lambda : 3)
|
||||||
self.assertEqual(proc.waitall([x, y, z]), [1, 2, 3])
|
self.assertEqual(proc.waitall([x, y, z]), [1, 2, 3])
|
||||||
e = coros.Event()
|
e = _event.Event()
|
||||||
x.link(e)
|
x.link(e)
|
||||||
self.assertEqual(e.wait(), 1)
|
self.assertEqual(e.wait(), 1)
|
||||||
x.unlink(e)
|
x.unlink(e)
|
||||||
e = coros.Event()
|
e = _event.Event()
|
||||||
x.link(e)
|
x.link(e)
|
||||||
self.assertEqual(e.wait(), 1)
|
self.assertEqual(e.wait(), 1)
|
||||||
self.assertEqual([proc.waitall([X]) for X in [x, y, z]], [[1], [2], [3]])
|
self.assertEqual([proc.waitall([X]) for X in [x, y, z]], [[1], [2], [3]])
|
||||||
@@ -358,7 +359,7 @@ class TestStuff(LimitedTestCase):
|
|||||||
self._test_multiple_listeners_error_unlink(p)
|
self._test_multiple_listeners_error_unlink(p)
|
||||||
|
|
||||||
def test_killing_unlinked(self):
|
def test_killing_unlinked(self):
|
||||||
e = coros.Event()
|
e = _event.Event()
|
||||||
def func():
|
def func():
|
||||||
try:
|
try:
|
||||||
raise ExpectedError('test_killing_unlinked')
|
raise ExpectedError('test_killing_unlinked')
|
||||||
|
@@ -19,7 +19,7 @@ import time
|
|||||||
import re
|
import re
|
||||||
from tests import skipped, skip_with_pyevent, LimitedTestCase, main
|
from tests import skipped, skip_with_pyevent, LimitedTestCase, main
|
||||||
|
|
||||||
from eventlet import api, tpool, debug
|
from eventlet import tpool, debug
|
||||||
import eventlet
|
import eventlet
|
||||||
|
|
||||||
one = 1
|
one = 1
|
||||||
@@ -156,8 +156,8 @@ class TestTpool(LimitedTestCase):
|
|||||||
@skip_with_pyevent
|
@skip_with_pyevent
|
||||||
def test_timeout(self):
|
def test_timeout(self):
|
||||||
import time
|
import time
|
||||||
api.exc_after(0.1, api.TimeoutError())
|
eventlet.Timeout(0.1, eventlet.TimeoutError())
|
||||||
self.assertRaises(api.TimeoutError,
|
self.assertRaises(eventlet.TimeoutError,
|
||||||
tpool.execute, time.sleep, 0.3)
|
tpool.execute, time.sleep, 0.3)
|
||||||
|
|
||||||
@skip_with_pyevent
|
@skip_with_pyevent
|
||||||
@@ -209,12 +209,12 @@ class TpoolLongTests(LimitedTestCase):
|
|||||||
obj = tpool.Proxy(Dummy())
|
obj = tpool.Proxy(Dummy())
|
||||||
count = 100
|
count = 100
|
||||||
for n in xrange(count):
|
for n in xrange(count):
|
||||||
api.sleep(random.random()/200.0)
|
eventlet.sleep(random.random()/200.0)
|
||||||
now = time.time()
|
now = time.time()
|
||||||
token = loopnum * count + n
|
token = loopnum * count + n
|
||||||
rv = obj.foo(now,token=token)
|
rv = obj.foo(now,token=token)
|
||||||
self.assertEquals(token, rv)
|
self.assertEquals(token, rv)
|
||||||
api.sleep(random.random()/200.0)
|
eventlet.sleep(random.random()/200.0)
|
||||||
|
|
||||||
pile = eventlet.GreenPile(10)
|
pile = eventlet.GreenPile(10)
|
||||||
for i in xrange(10):
|
for i in xrange(10):
|
||||||
|
@@ -138,7 +138,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestHttpd, self).tearDown()
|
super(TestHttpd, self).tearDown()
|
||||||
greenthread.kill(self.killer)
|
greenthread.kill(self.killer)
|
||||||
api.sleep(0)
|
eventlet.sleep(0)
|
||||||
|
|
||||||
def spawn_server(self, **kwargs):
|
def spawn_server(self, **kwargs):
|
||||||
"""Spawns a new wsgi server with the given arguments.
|
"""Spawns a new wsgi server with the given arguments.
|
||||||
@@ -155,7 +155,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
new_kwargs.update(kwargs)
|
new_kwargs.update(kwargs)
|
||||||
|
|
||||||
if 'sock' not in new_kwargs:
|
if 'sock' not in new_kwargs:
|
||||||
new_kwargs['sock'] = api.tcp_listener(('localhost', 0))
|
new_kwargs['sock'] = eventlet.listen(('localhost', 0))
|
||||||
|
|
||||||
self.port = new_kwargs['sock'].getsockname()[1]
|
self.port = new_kwargs['sock'].getsockname()[1]
|
||||||
self.killer = eventlet.spawn_n(
|
self.killer = eventlet.spawn_n(
|
||||||
@@ -163,7 +163,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
**new_kwargs)
|
**new_kwargs)
|
||||||
|
|
||||||
def test_001_server(self):
|
def test_001_server(self):
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
|
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
@@ -176,7 +176,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
self.assert_(result.endswith('hello world'))
|
self.assert_(result.endswith('hello world'))
|
||||||
|
|
||||||
def test_002_keepalive(self):
|
def test_002_keepalive(self):
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
|
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
@@ -190,19 +190,19 @@ class TestHttpd(LimitedTestCase):
|
|||||||
|
|
||||||
def test_003_passing_non_int_to_read(self):
|
def test_003_passing_non_int_to_read(self):
|
||||||
# This should go in greenio_test
|
# This should go in greenio_test
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
|
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||||
fd.flush()
|
fd.flush()
|
||||||
cancel = api.exc_after(1, RuntimeError)
|
cancel = eventlet.Timeout(1, RuntimeError)
|
||||||
self.assertRaises(TypeError, fd.read, "This shouldn't work")
|
self.assertRaises(TypeError, fd.read, "This shouldn't work")
|
||||||
cancel.cancel()
|
cancel.cancel()
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
def test_004_close_keepalive(self):
|
def test_004_close_keepalive(self):
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
|
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
@@ -226,7 +226,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
print out.read()
|
print out.read()
|
||||||
|
|
||||||
def test_006_reject_long_urls(self):
|
def test_006_reject_long_urls(self):
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
path_parts = []
|
path_parts = []
|
||||||
for ii in range(3000):
|
for ii in range(3000):
|
||||||
@@ -252,7 +252,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
start_response('200 OK', [('Content-type', 'text/plain')])
|
start_response('200 OK', [('Content-type', 'text/plain')])
|
||||||
return ['a is %s, body is %s' % (a, body)]
|
return ['a is %s, body is %s' % (a, body)]
|
||||||
self.site.application = new_app
|
self.site.application = new_app
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
request = '\r\n'.join((
|
request = '\r\n'.join((
|
||||||
'POST / HTTP/1.0',
|
'POST / HTTP/1.0',
|
||||||
@@ -271,7 +271,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
def test_008_correctresponse(self):
|
def test_008_correctresponse(self):
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
|
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
@@ -289,7 +289,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
|
|
||||||
def test_009_chunked_response(self):
|
def test_009_chunked_response(self):
|
||||||
self.site.application = chunked_app
|
self.site.application = chunked_app
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
|
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
@@ -299,7 +299,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
|
|
||||||
def test_010_no_chunked_http_1_0(self):
|
def test_010_no_chunked_http_1_0(self):
|
||||||
self.site.application = chunked_app
|
self.site.application = chunked_app
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
|
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
@@ -309,7 +309,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
|
|
||||||
def test_011_multiple_chunks(self):
|
def test_011_multiple_chunks(self):
|
||||||
self.site.application = big_chunks
|
self.site.application = big_chunks
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
|
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
@@ -346,7 +346,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
server_sock = api.ssl_listener(('localhost', 0), certificate_file, private_key_file)
|
server_sock = api.ssl_listener(('localhost', 0), certificate_file, private_key_file)
|
||||||
self.spawn_server(sock=server_sock, site=wsgi_app)
|
self.spawn_server(sock=server_sock, site=wsgi_app)
|
||||||
|
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
sock = util.wrap_ssl(sock)
|
sock = util.wrap_ssl(sock)
|
||||||
sock.write('POST /foo HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\nContent-length:3\r\n\r\nabc')
|
sock.write('POST /foo HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\nContent-length:3\r\n\r\nabc')
|
||||||
result = sock.read(8192)
|
result = sock.read(8192)
|
||||||
@@ -362,7 +362,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
server_sock = api.ssl_listener(('localhost', 0), certificate_file, private_key_file)
|
server_sock = api.ssl_listener(('localhost', 0), certificate_file, private_key_file)
|
||||||
self.spawn_server(sock=server_sock, site=wsgi_app)
|
self.spawn_server(sock=server_sock, site=wsgi_app)
|
||||||
|
|
||||||
sock = api.connect_tcp(('localhost', server_sock.getsockname()[1]))
|
sock = eventlet.connect(('localhost', server_sock.getsockname()[1]))
|
||||||
sock = util.wrap_ssl(sock)
|
sock = util.wrap_ssl(sock)
|
||||||
sock.write('GET /foo HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
sock.write('GET /foo HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||||
result = sock.read(8192)
|
result = sock.read(8192)
|
||||||
@@ -370,7 +370,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
|
|
||||||
def test_014_chunked_post(self):
|
def test_014_chunked_post(self):
|
||||||
self.site.application = chunked_post
|
self.site.application = chunked_post
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('PUT /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
|
fd.write('PUT /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
|
||||||
'Transfer-Encoding: chunked\r\n\r\n'
|
'Transfer-Encoding: chunked\r\n\r\n'
|
||||||
@@ -382,7 +382,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
response = fd.read()
|
response = fd.read()
|
||||||
self.assert_(response == 'oh hai', 'invalid response %s' % response)
|
self.assert_(response == 'oh hai', 'invalid response %s' % response)
|
||||||
|
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('PUT /b HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
|
fd.write('PUT /b HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
|
||||||
'Transfer-Encoding: chunked\r\n\r\n'
|
'Transfer-Encoding: chunked\r\n\r\n'
|
||||||
@@ -394,7 +394,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
response = fd.read()
|
response = fd.read()
|
||||||
self.assert_(response == 'oh hai', 'invalid response %s' % response)
|
self.assert_(response == 'oh hai', 'invalid response %s' % response)
|
||||||
|
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('PUT /c HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
|
fd.write('PUT /c HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
|
||||||
'Transfer-Encoding: chunked\r\n\r\n'
|
'Transfer-Encoding: chunked\r\n\r\n'
|
||||||
@@ -408,14 +408,14 @@ class TestHttpd(LimitedTestCase):
|
|||||||
|
|
||||||
def test_015_write(self):
|
def test_015_write(self):
|
||||||
self.site.application = use_write
|
self.site.application = use_write
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('GET /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
fd.write('GET /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||||
fd.flush()
|
fd.flush()
|
||||||
response_line, headers, body = read_http(sock)
|
response_line, headers, body = read_http(sock)
|
||||||
self.assert_('content-length' in headers)
|
self.assert_('content-length' in headers)
|
||||||
|
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('GET /b HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
fd.write('GET /b HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||||
fd.flush()
|
fd.flush()
|
||||||
@@ -432,7 +432,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
start_response('200 OK', [('Content-Length', '7')])
|
start_response('200 OK', [('Content-Length', '7')])
|
||||||
return ['testing']
|
return ['testing']
|
||||||
self.site.application = wsgi_app
|
self.site.application = wsgi_app
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('GET /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
fd.write('GET /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||||
fd.flush()
|
fd.flush()
|
||||||
@@ -470,7 +470,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
|
|
||||||
server_coro = eventlet.spawn(server, sock, wsgi_app, self.logfile)
|
server_coro = eventlet.spawn(server, sock, wsgi_app, self.logfile)
|
||||||
|
|
||||||
client = api.connect_tcp(('localhost', sock.getsockname()[1]))
|
client = eventlet.connect(('localhost', sock.getsockname()[1]))
|
||||||
client = util.wrap_ssl(client)
|
client = util.wrap_ssl(client)
|
||||||
client.write('X') # non-empty payload so that SSL handshake occurs
|
client.write('X') # non-empty payload so that SSL handshake occurs
|
||||||
greenio.shutdown_safe(client)
|
greenio.shutdown_safe(client)
|
||||||
@@ -482,7 +482,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
def test_018_http_10_keepalive(self):
|
def test_018_http_10_keepalive(self):
|
||||||
# verify that if an http/1.0 client sends connection: keep-alive
|
# verify that if an http/1.0 client sends connection: keep-alive
|
||||||
# that we don't close the connection
|
# that we don't close the connection
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
|
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
@@ -508,7 +508,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
return ['hello!']
|
return ['hello!']
|
||||||
|
|
||||||
self.site.application = use_fieldstorage
|
self.site.application = use_fieldstorage
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
|
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
@@ -522,7 +522,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
self.assert_('hello!' in fd.read())
|
self.assert_('hello!' in fd.read())
|
||||||
|
|
||||||
def test_020_x_forwarded_for(self):
|
def test_020_x_forwarded_for(self):
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
sock.sendall('GET / HTTP/1.1\r\nHost: localhost\r\nX-Forwarded-For: 1.2.3.4, 5.6.7.8\r\n\r\n')
|
sock.sendall('GET / HTTP/1.1\r\nHost: localhost\r\nX-Forwarded-For: 1.2.3.4, 5.6.7.8\r\n\r\n')
|
||||||
sock.recv(1024)
|
sock.recv(1024)
|
||||||
sock.close()
|
sock.close()
|
||||||
@@ -532,7 +532,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
self.logfile = StringIO()
|
self.logfile = StringIO()
|
||||||
self.spawn_server(log_x_forwarded_for=False)
|
self.spawn_server(log_x_forwarded_for=False)
|
||||||
|
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
sock.sendall('GET / HTTP/1.1\r\nHost: localhost\r\nX-Forwarded-For: 1.2.3.4, 5.6.7.8\r\n\r\n')
|
sock.sendall('GET / HTTP/1.1\r\nHost: localhost\r\nX-Forwarded-For: 1.2.3.4, 5.6.7.8\r\n\r\n')
|
||||||
sock.recv(1024)
|
sock.recv(1024)
|
||||||
sock.close()
|
sock.close()
|
||||||
@@ -542,11 +542,11 @@ class TestHttpd(LimitedTestCase):
|
|||||||
|
|
||||||
def test_socket_remains_open(self):
|
def test_socket_remains_open(self):
|
||||||
greenthread.kill(self.killer)
|
greenthread.kill(self.killer)
|
||||||
server_sock = api.tcp_listener(('localhost', 0))
|
server_sock = eventlet.listen(('localhost', 0))
|
||||||
server_sock_2 = server_sock.dup()
|
server_sock_2 = server_sock.dup()
|
||||||
self.spawn_server(sock=server_sock_2)
|
self.spawn_server(sock=server_sock_2)
|
||||||
# do a single req/response to verify it's up
|
# do a single req/response to verify it's up
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||||
fd.flush()
|
fd.flush()
|
||||||
@@ -565,7 +565,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
except socket.error, exc:
|
except socket.error, exc:
|
||||||
self.assertEqual(exc[0], errno.EBADF)
|
self.assertEqual(exc[0], errno.EBADF)
|
||||||
self.spawn_server(sock=server_sock)
|
self.spawn_server(sock=server_sock)
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||||
fd.flush()
|
fd.flush()
|
||||||
@@ -586,7 +586,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
start_response('200 OK', [('Content-type', 'text/plain')])
|
start_response('200 OK', [('Content-type', 'text/plain')])
|
||||||
return []
|
return []
|
||||||
self.site.application = clobberin_time
|
self.site.application = clobberin_time
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('GET / HTTP/1.1\r\n'
|
fd.write('GET / HTTP/1.1\r\n'
|
||||||
'Host: localhost\r\n'
|
'Host: localhost\r\n'
|
||||||
@@ -604,7 +604,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
self.spawn_server(custom_pool=p)
|
self.spawn_server(custom_pool=p)
|
||||||
|
|
||||||
# this stuff is copied from test_001_server, could be better factored
|
# this stuff is copied from test_001_server, could be better factored
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||||
@@ -615,7 +615,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
self.assert_(result.endswith('hello world'))
|
self.assert_(result.endswith('hello world'))
|
||||||
|
|
||||||
def test_023_bad_content_length(self):
|
def test_023_bad_content_length(self):
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\nContent-length: argh\r\n\r\n')
|
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\nContent-length: argh\r\n\r\n')
|
||||||
@@ -636,7 +636,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
start_response('200 OK', [('Content-Length', str(len(text)))])
|
start_response('200 OK', [('Content-Length', str(len(text)))])
|
||||||
return [text]
|
return [text]
|
||||||
self.site.application = wsgi_app
|
self.site.application = wsgi_app
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('PUT / HTTP/1.1\r\nHost: localhost\r\nContent-length: 1025\r\nExpect: 100-continue\r\n\r\n')
|
fd.write('PUT / HTTP/1.1\r\nHost: localhost\r\nContent-length: 1025\r\nExpect: 100-continue\r\n\r\n')
|
||||||
fd.flush()
|
fd.flush()
|
||||||
@@ -677,7 +677,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
sys.stderr = self.logfile
|
sys.stderr = self.logfile
|
||||||
api.sleep(0) # need to enter server loop
|
api.sleep(0) # need to enter server loop
|
||||||
try:
|
try:
|
||||||
api.connect_tcp(('localhost', self.port))
|
eventlet.connect(('localhost', self.port))
|
||||||
self.fail("Didn't expect to connect")
|
self.fail("Didn't expect to connect")
|
||||||
except socket.error, exc:
|
except socket.error, exc:
|
||||||
self.assertEquals(exc[0], errno.ECONNREFUSED)
|
self.assertEquals(exc[0], errno.ECONNREFUSED)
|
||||||
@@ -690,7 +690,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
|
|
||||||
def test_026_log_format(self):
|
def test_026_log_format(self):
|
||||||
self.spawn_server(log_format="HI %(request_line)s HI")
|
self.spawn_server(log_format="HI %(request_line)s HI")
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
sock.sendall('GET /yo! HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
sock.sendall('GET /yo! HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||||
sock.recv(1024)
|
sock.recv(1024)
|
||||||
sock.close()
|
sock.close()
|
||||||
@@ -701,7 +701,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
# and we're not speaking with a 1.1 client, that we
|
# and we're not speaking with a 1.1 client, that we
|
||||||
# close the connection
|
# close the connection
|
||||||
self.site.application = chunked_app
|
self.site.application = chunked_app
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
|
|
||||||
sock.sendall('GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n')
|
sock.sendall('GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n')
|
||||||
|
|
||||||
@@ -714,7 +714,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
# verify that if an http/1.0 client sends connection: keep-alive
|
# verify that if an http/1.0 client sends connection: keep-alive
|
||||||
# and the server doesn't accept keep-alives, we close the connection
|
# and the server doesn't accept keep-alives, we close the connection
|
||||||
self.spawn_server(keepalive=False)
|
self.spawn_server(keepalive=False)
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
|
|
||||||
sock.sendall('GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n')
|
sock.sendall('GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n')
|
||||||
@@ -723,7 +723,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
|
|
||||||
def test_027_keepalive_chunked(self):
|
def test_027_keepalive_chunked(self):
|
||||||
self.site.application = chunked_post
|
self.site.application = chunked_post
|
||||||
sock = api.connect_tcp(('localhost', self.port))
|
sock = eventlet.connect(('localhost', self.port))
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
fd.write('PUT /a HTTP/1.1\r\nHost: localhost\r\nTransfer-Encoding: chunked\r\n\r\n10\r\n0123456789abcdef\r\n0\r\n\r\n')
|
fd.write('PUT /a HTTP/1.1\r\nHost: localhost\r\nTransfer-Encoding: chunked\r\n\r\n10\r\n0123456789abcdef\r\n0\r\n\r\n')
|
||||||
fd.flush()
|
fd.flush()
|
||||||
@@ -752,7 +752,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
srv_sock = api.ssl_listener(('localhost', 0), certificate_file, private_key_file)
|
srv_sock = api.ssl_listener(('localhost', 0), certificate_file, private_key_file)
|
||||||
port = srv_sock.getsockname()[1]
|
port = srv_sock.getsockname()[1]
|
||||||
g = eventlet.spawn_n(server, srv_sock)
|
g = eventlet.spawn_n(server, srv_sock)
|
||||||
client = api.connect_tcp(('localhost', port))
|
client = eventlet.connect(('localhost', port))
|
||||||
if data: # send non-ssl request
|
if data: # send non-ssl request
|
||||||
client.sendall(data)
|
client.sendall(data)
|
||||||
else: # close sock prematurely
|
else: # close sock prematurely
|
||||||
@@ -762,7 +762,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
# make another request to ensure the server's still alive
|
# make another request to ensure the server's still alive
|
||||||
try:
|
try:
|
||||||
from eventlet.green import ssl
|
from eventlet.green import ssl
|
||||||
client = ssl.wrap_socket(api.connect_tcp(('localhost', port)))
|
client = ssl.wrap_socket(eventlet.connect(('localhost', port)))
|
||||||
client.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
client.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||||
result = client.read()
|
result = client.read()
|
||||||
self.assert_(result.startswith('HTTP'), result)
|
self.assert_(result.startswith('HTTP'), result)
|
||||||
@@ -777,7 +777,7 @@ class TestHttpd(LimitedTestCase):
|
|||||||
yield ""
|
yield ""
|
||||||
|
|
||||||
self.site.application = zero_chunked_app
|
self.site.application = zero_chunked_app
|
||||||
sock = api.connect_tcp(
|
sock = eventlet.connect(
|
||||||
('localhost', self.port))
|
('localhost', self.port))
|
||||||
|
|
||||||
fd = sock.makefile()
|
fd = sock.makefile()
|
||||||
|
Reference in New Issue
Block a user