Commit 26f8bf35 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[master] avoid using 'with' protocol for socket.socket. it doesn't work < 3.2.

this should fix test failures reported by buildbots.  confirmed, committing
at my discretion.
parent 4eb6ec7a
...@@ -199,16 +199,21 @@ class TestUtility(unittest.TestCase): ...@@ -199,16 +199,21 @@ class TestUtility(unittest.TestCase):
def is_blocking(fd): def is_blocking(fd):
return (fcntl.fcntl(fd, fcntl.F_GETFL) & os.O_NONBLOCK) == 0 return (fcntl.fcntl(fd, fcntl.F_GETFL) & os.O_NONBLOCK) == 0
with socket.socket(socket.AF_INET, socket.SOCK_STREAM, # socket.socket doesn't support the 'with' statement before Python
socket.IPPROTO_TCP) as sock: # 3.2, so we'll close it ourselves (while it's not completely exception
# By default socket is made blocking # safe, it should be acceptable for a test case)
self.assertTrue(is_blocking(sock.fileno())) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
# make_blocking(False) makes it non blocking socket.IPPROTO_TCP)
xfrout.make_blocking(sock.fileno(), False) # By default socket is made blocking
self.assertFalse(is_blocking(sock.fileno())) self.assertTrue(is_blocking(sock.fileno()))
# make_blocking(True) makes it blocking again # make_blocking(False) makes it non blocking
xfrout.make_blocking(sock.fileno(), True) xfrout.make_blocking(sock.fileno(), False)
self.assertTrue(is_blocking(sock.fileno())) self.assertFalse(is_blocking(sock.fileno()))
# make_blocking(True) makes it blocking again
xfrout.make_blocking(sock.fileno(), True)
self.assertTrue(is_blocking(sock.fileno()))
sock.close()
class TestXfroutSessionBase(unittest.TestCase): class TestXfroutSessionBase(unittest.TestCase):
'''Base class for tests related to xfrout sessions '''Base class for tests related to xfrout sessions
......
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