Browse Source

[trac1001] fix code style and update unittest

chenzhengzhang 14 years ago
parent
commit
9395f12c95

+ 5 - 6
src/lib/python/isc/notify/notify_out.py

@@ -54,10 +54,6 @@ class ZoneNotifyInfo:
     '''This class keeps track of notify-out information for one zone.'''
 
     def __init__(self, zone_name_, class_):
-        '''notify_timeout_: absolute time for next notify reply. when the zone
-        is preparing for sending notify message, notify_timeout_ is set to now,
-        that means the first sending is triggered by the 'Timeout' mechanism.
-        '''
         self._notify_current = None
         self._slave_index = 0
         self._sock = None
@@ -66,8 +62,11 @@ class ZoneNotifyInfo:
         self.zone_name = zone_name_
         self.zone_class = class_
         self.notify_msg_id = 0
+        # Absolute time for next notify reply. When the zone is preparing for
+        # sending notify message, notify_timeout_ is set to now, that means
+        # the first sending is triggered by the 'Timeout' mechanism.
         self.notify_timeout = None
-        self.notify_try_num = 0  #Notify times sending to one target.
+        self.notify_try_num = 0  # Notify times sending to one target.
 
     def set_next_notify_target(self):
         if self._slave_index < (len(self.notify_slaves) - 1):
@@ -377,8 +376,8 @@ class NotifyOut:
                 self._log_msg('info', 'notify to %s: retried exceeded' % addr_to_str(tgt))
                 self._notify_next_target(zone_notify_info)
             else:
-                retry_timeout = _NOTIFY_TIMEOUT * pow(2, zone_notify_info.notify_try_num)
                 # set exponential backoff according rfc1996 section 3.6
+                retry_timeout = _NOTIFY_TIMEOUT * pow(2, zone_notify_info.notify_try_num)
                 zone_notify_info.notify_timeout = time.time() + retry_timeout
                 self._send_notify_message_udp(zone_notify_info, tgt)
 

+ 24 - 2
src/lib/python/isc/notify/tests/notify_out_test.py

@@ -376,9 +376,31 @@ class TestNotifyOut(unittest.TestCase):
 
     def test_shutdown(self):
         thread = self._notify.dispatcher()
-        # nonblock_event will be cleared since there are no notifying zones.
-        self.assertFalse(self._notify._nonblock_event.isSet())
         self.assertTrue(thread.is_alive())
+        # nonblock_event won't be setted since there are no notifying zones.
+        self.assertFalse(self._notify._nonblock_event.isSet())
+
+        # set nonblock_event manually
+        self._notify._nonblock_event.set()
+        # nonblock_event will be cleared soon since there are no notifying zones.
+        while (self._notify._nonblock_event.isSet()):
+            pass
+        self.assertFalse(self._notify._nonblock_event.isSet())
+
+        # send notify
+        example_net_info = self._notify._notify_infos[('example.net.', 'IN')]
+        example_net_info.notify_slaves = [('127.0.0.1', 53)]
+        example_net_info.create_socket('127.0.0.1')
+        self._notify.send_notify('example.net')
+        self.assertTrue(self._notify._nonblock_event.isSet())
+        # set notify_try_num to _MAX_NOTIFY_TRY_NUM, zone 'example.net' will be removed
+        # from notifying zones soon and nonblock_event will be cleared since there is no 
+        # notifying zone left.
+        example_net_info.notify_try_num = notify_out._MAX_NOTIFY_TRY_NUM
+        while (self._notify._nonblock_event.isSet()):
+            pass
+        self.assertFalse(self._notify._nonblock_event.isSet())
+
         self._notify.shutdown()
         # nonblock_event should have been setted to stop waiting.
         self.assertTrue(self._notify._nonblock_event.isSet())