Commit 459fe269 authored by Denis Bilenko's avatar Denis Bilenko

update tests with regard to removal of tcp_listener and bind_socket_and_listen from gevent.socket

parent 0dabcf6b
......@@ -372,3 +372,22 @@ def walk_modules(basedir=None, modpath=None, include_so=False):
yield path, modpath + fn[:-5]
else:
yield path, modpath + fn[:-3]
def bind_and_listen(sock, address=('', 0), backlog=50, reuse_addr=True):
from socket import SOL_SOCKET, SO_REUSEADDR, error
if reuse_addr:
try:
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, sock.getsockopt(SOL_SOCKET, SO_REUSEADDR) | 1)
except error:
pass
sock.bind(address)
sock.listen(backlog)
def tcp_listener(address, backlog=50, reuse_addr=True):
"""A shortcut to create a TCP socket, bind it and put it into listening state."""
from gevent import socket
sock = socket.socket()
bind_and_listen(sock)
return sock
......@@ -17,7 +17,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from greentest import TestCase, main
from greentest import TestCase, main, tcp_listener
import gevent
from gevent import socket
......@@ -65,12 +65,12 @@ class TestGreenIo(TestCase):
assert fd.read() == ''
fd.close()
server = socket.tcp_listener(('0.0.0.0', 0))
server = tcp_listener(('0.0.0.0', 0))
server_greenlet = gevent.spawn(accept_close_early, server)
did_it_work(server)
server_greenlet.kill()
server = socket.tcp_listener(('0.0.0.0', 0))
server = tcp_listener(('0.0.0.0', 0))
server_greenlet = gevent.spawn(accept_close_late, server)
did_it_work(server)
server_greenlet.kill()
......@@ -92,7 +92,7 @@ class TestGreenIo(TestCase):
finally:
listener.close()
server = socket.tcp_listener(('0.0.0.0', 0))
server = tcp_listener(('0.0.0.0', 0))
gevent.spawn(accept_once, server)
client = socket.create_connection(('127.0.0.1', server.getsockname()[1]))
fd = client.makefile()
......
......@@ -12,7 +12,7 @@ class TestTCP(greentest.TestCase):
def setUp(self):
greentest.TestCase.setUp(self)
self.listener = socket.tcp_listener(('127.0.0.1', 0))
self.listener = greentest.tcp_listener(('127.0.0.1', 0))
def tearDown(self):
del self.listener
......@@ -127,7 +127,7 @@ if hasattr(socket, 'ssl'):
import _socket
r = _socket.socket()
sock = socket.ssl(r, private_key, certificate)
socket.bind_and_listen(sock, address)
greentest.bind_and_listen(sock, address)
return sock
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment