Commit 4a7154c6 authored by Likun Zhang's avatar Likun Zhang
Browse files

code cleanup and fix the error in the test case.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac352@3346 e5f2f494-b856-4b98-b285-d166d9295462
parent 4eefe424
......@@ -54,7 +54,7 @@ class ServeMixIn:
'''
def __init__(self):
self.__read_sock, self.__write_sock = socket.socketpair()
self.__is_shut_down = threading.Event()
self._is_shut_down = threading.Event()
def serve_forever(self, poll_interval=None):
''' Overrides the serve_forever([poll_interval]) in class
......@@ -73,7 +73,6 @@ class ServeMixIn:
if err.args[0] == EINTR:
continue
else:
sys.stderr.write("Error with select(), %s\n", err)
break
if self.__read_sock in r:
......@@ -81,7 +80,7 @@ class ServeMixIn:
else:
self._handle_request_noblock()
self.__is_shut_down.set()
self._is_shut_down.set()
def shutdown(self):
'''Stops the serve_forever loop.
......@@ -90,4 +89,4 @@ class ServeMixIn:
in another thread when serve_forever is running, or it will block.
'''
self.__write_sock.send(SOCK_DATA) # make self.__read_sock readable.
self.__is_shut_down.wait() # wait until the serve thread terminate
self._is_shut_down.wait() # wait until the serve thread terminate
......@@ -47,18 +47,15 @@ class TestServeMixIn(unittest.TestCase):
server = MyServer(('127.0.0.1', 0), MyHandler)
ip, port = server.server_address
server_thread = threading.Thread(target=server.serve_forever)
server_thread.setDaemon(True)
server_thread.start()
msg = b'senddata'
self.assertEqual(msg, send_and_get_reply(ip, port, msg))
self.assertTrue(server_thread.is_alive())
# Now shutdown the server
server.shutdown()
# Sleep a while, make sure the thread has finished.
time.sleep(0.1)
self.assertFalse(server_thread.is_alive())
self.assertFalse(server._is_shut_down.is_set())
server.shutdown() # Now shutdown the server
self.assertTrue(server._is_shut_down.is_set())
if __name__== "__main__":
unittest.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