Commit 7cf8eefa authored by Jerry's avatar Jerry
Browse files

fix a zonemgr test case issue(issue on exiting thread)


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac335@3165 e5f2f494-b856-4b98-b285-d166d9295462
parent b04a8bea
......@@ -396,7 +396,13 @@ class TestZonemgrRefresh(unittest.TestCase):
listener.start()
# Sleep 1 sec to ensure that the timer thread has enough time to run.
time.sleep(1)
# Shut down the timer thread
self.zone_refresh.shutdown()
main_thread = threading.currentThread()
for th in threading.enumerate():
if th is main_thread:
continue
th.join()
# After running timer, the zone's state should become "refreshing".
zone_state = self.zone_refresh._zonemgr_refresh_info[ZONE_NAME_CLASS1_IN]["zone_state"]
self.assertTrue("refresh_timeout" in self.zone_refresh._zonemgr_refresh_info[ZONE_NAME_CLASS1_IN].keys())
......@@ -404,12 +410,16 @@ class TestZonemgrRefresh(unittest.TestCase):
def test_shutdown(self):
self.zone_refresh._check_sock = self.zone_refresh._master_socket
listener = threading.Thread(target=self.zone_refresh.run_timer)
listener = threading.Thread(target = self.zone_refresh.run_timer)
listener.start()
self.assertTrue(listener.is_alive())
# Shut down the timer thread
self.zone_refresh.shutdown()
# Sleep 1 sec to ensure that the timer thread has enough time to exit.
time.sleep(1)
main_thread = threading.currentThread()
for th in threading.enumerate():
if th is main_thread:
continue
th.join()
self.assertFalse(listener.is_alive())
def tearDown(self):
......
......@@ -369,9 +369,10 @@ class ZonemgrRefresh:
if not rlist: # timer timeout
continue
if self._read_sock in rlist: # awaken by shutdown socket
self._read_sock.recv(32)
continue
if self._check_sock in rlist: # awaken by check socket
self._check_sock.recv(5)
self._check_sock.recv(32)
self._is_shut_down.set()
......@@ -389,7 +390,7 @@ class Zonemgr:
self._db_file = self.get_db_file()
# Create socket pair for communicating between main thread and zonemgr timer thread
self._master_socket, self._slave_socket = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
self._zone_refresh= ZonemgrRefresh(self._cc, self._db_file, self._slave_socket)
self._zone_refresh = ZonemgrRefresh(self._cc, self._db_file, self._slave_socket)
self._start_zone_refresh_timer()
self._lock = threading.Lock()
......
Supports Markdown
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