Commit 4704731f authored by Denis Bilenko's avatar Denis Bilenko

update test__backdoor.py

parent 39e45c74
...@@ -3,21 +3,22 @@ import gevent ...@@ -3,21 +3,22 @@ import gevent
from gevent import socket from gevent import socket
from gevent import backdoor from gevent import backdoor
class Test(greentest.TestCase): class Test(greentest.TestCase):
def test(self): def test(self):
g = gevent.spawn(backdoor.backdoor_server, socket.tcp_listener(('127.0.0.1', 7891))) server = backdoor.BackdoorServer.spawn(('127.0.0.1', 7891))
gevent.sleep(0.1) gevent.sleep(0.1)
s = socket.create_connection(('127.0.0.1', 7891)) fileobj = socket.create_connection(('127.0.0.1', 7891)).makefile()
f = s.makefile()
while True: while True:
line = gevent.with_timeout(0.1, f.readline, timeout_value=None) line = gevent.with_timeout(0.1, fileobj.readline, timeout_value=None)
if line is None: if line is None:
break break
s.sendall('2+2\r\n') fileobj.write('2+2\r\n')
l = f.readline() fileobj.flush()
assert l.strip() == '4', repr(l) line = fileobj.readline()
g.kill(block=True) assert line.strip() == '4', repr(line)
server.kill(block=True)
if __name__ == '__main__': if __name__ == '__main__':
......
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