BIND 10 trac1175_reapplied, updated. cef9bd05810891bb4d0b44f0dc3ad47ee8161784 [1175] correct the comment according to the purpose of the retry

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Sep 27 06:37:54 UTC 2011


The branch, trac1175_reapplied has been updated
       via  cef9bd05810891bb4d0b44f0dc3ad47ee8161784 (commit)
       via  9a77593f1015bbbe7bca2e95e7b20a18d66a9f0f (commit)
       via  a881def076ce58f3a46303094b4bffd51f24b1b4 (commit)
       via  2d07ef93c566cc2d801bc9d3c0d55d5794bbc102 (commit)
       via  21358e1c1b8d3027ae10e3da656dc351fd17bfae (commit)
       via  6f4ae07aad42cb8cf474d35c4459e42e126556b3 (commit)
      from  3e116588ff10cd3c18db8539163eb4fa0d46202c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit cef9bd05810891bb4d0b44f0dc3ad47ee8161784
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Sep 26 22:13:09 2011 +0900

    [1175] correct the comment according to the purpose of the retry

commit 9a77593f1015bbbe7bca2e95e7b20a18d66a9f0f
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Sep 26 22:12:48 2011 +0900

    [1175] correct the names and comments of the functions according to their
    purposes

commit a881def076ce58f3a46303094b4bffd51f24b1b4
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Sep 26 18:35:22 2011 +0900

    [1175] remove the two conditions because they do the same tests for IPv4
    whether IPv6 is enabled or not

commit 2d07ef93c566cc2d801bc9d3c0d55d5794bbc102
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Sep 26 18:04:13 2011 +0900

    [1175] modify b10-stats_test.py, b10-stats-httpd_test.py and test_utils.py
    
     - exclude the setup of handler in SIGALRM and add it as an external
       function in the SignalHandler class in test_utils.py
    
     - define the function in that class to reset the handler in
       test_utils.py, and add it in tearDown() in each testcase

commit 21358e1c1b8d3027ae10e3da656dc351fd17bfae
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Sep 26 15:46:30 2011 +0900

    [1175] fix double hash signs

commit 6f4ae07aad42cb8cf474d35c4459e42e126556b3
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Sep 26 22:24:35 2011 +0900

    [1175] correct the comment of the function according to its purpose

-----------------------------------------------------------------------

Summary of changes:
 src/bin/stats/tests/b10-stats-httpd_test.py |   78 ++++++++++++---------------
 src/bin/stats/tests/b10-stats_test.py       |   13 ++---
 src/bin/stats/tests/test_utils.py           |   23 ++++++++-
 3 files changed, 62 insertions(+), 52 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/stats/tests/b10-stats-httpd_test.py b/src/bin/stats/tests/b10-stats-httpd_test.py
index a066251..22b91c1 100644
--- a/src/bin/stats/tests/b10-stats-httpd_test.py
+++ b/src/bin/stats/tests/b10-stats-httpd_test.py
@@ -32,13 +32,12 @@ import time
 import threading
 import http.client
 import xml.etree.ElementTree
-import signal
 import random
 
 import isc
 import stats_httpd
 import stats
-from test_utils import BaseModules, ThreadingServerManager, MyStats, MyStatsHttpd, send_command, send_shutdown
+from test_utils import BaseModules, ThreadingServerManager, MyStats, MyStatsHttpd, SignalHandler, send_command, send_shutdown
 
 DUMMY_DATA = {
     'Boss' : {
@@ -58,9 +57,14 @@ DUMMY_DATA = {
     }
 
 def get_availaddr(address='127.0.0.1', port=8001):
-    """returns tuple of address and port available to listen on the
-    platform. Default port range is between 8001 and 65535. If port is
-    over flow(greater than 65535), OverflowError is thrown"""
+    """returns a tuple of address and port which is available to
+    listen on the platform. The first argument is a address for
+    search. The second argument is a port for search. If a set of
+    address and port is failed on the search for the availability, the
+    port number is increased and it goes on the next trial until the
+    available set of address and port is looked up. If the port number
+    reaches over 65535, it may stop the search and raise a
+    OverflowError exception."""
     while True:
         for addr in socket.getaddrinfo(
             address, port, 0,
@@ -95,9 +99,8 @@ def is_ipv6_enabled(address='::1', port=8001):
 class TestHttpHandler(unittest.TestCase):
     """Tests for HttpHandler class"""
     def setUp(self):
-        # deadlock will be killed afer 20 secs
-        signal.signal(signal.SIGALRM, self.my_signal_handler)
-        signal.alarm(20)
+        # set the signal handler for deadlock
+        self.sig_handler = SignalHandler(self.fail)
         self.base = BaseModules()
         self.stats_server = ThreadingServerManager(MyStats)
         self.stats = self.stats_server.server
@@ -115,9 +118,8 @@ class TestHttpHandler(unittest.TestCase):
         self.stats_httpd_server.shutdown()
         self.stats_server.shutdown()
         self.base.shutdown()
-
-    def my_signal_handler(self, signal, frame):
-        self.fail("A deadlock might be detected")
+        # reset the signal handler
+        self.sig_handler.reset()
 
     def test_do_GET(self):
         self.assertTrue(type(self.stats_httpd.httpd) is list)
@@ -197,7 +199,7 @@ class TestHttpHandler(unittest.TestCase):
         self.assertEqual(response.getheader('Location'),
                          "http://%s:%d%s" % (self.address, self.port, stats_httpd.XML_URL_PATH))
 
-        # # 404 NotFound
+        # 404 NotFound
         self.client._http_vsn_str = 'HTTP/1.0'
         self.client.putrequest('GET', '/path/to/foo/bar')
         self.client.endheaders()
@@ -280,18 +282,16 @@ class TestHttpServerError(unittest.TestCase):
 class TestHttpServer(unittest.TestCase):
     """Tests for HttpServer class"""
     def setUp(self):
-        # deadlock will be killed afer 20 secs
-        signal.signal(signal.SIGALRM, self.my_signal_handler)
-        signal.alarm(20)
+        # set the signal handler for deadlock
+        self.sig_handler = SignalHandler(self.fail)
         self.base = BaseModules()
 
     def tearDown(self):
         if hasattr(self, "stats_httpd"):
             self.stats_httpd.stop()
         self.base.shutdown()
-
-    def my_signal_handler(self, signal, frame):
-        self.fail("A deadlock might be detected")
+        # reset the signal handler
+        self.sig_handler.reset()
 
     def test_httpserver(self):
         self.stats_httpd = MyStatsHttpd(get_availaddr())
@@ -313,9 +313,8 @@ class TestStatsHttpd(unittest.TestCase):
     """Tests for StatsHttpd class"""
 
     def setUp(self):
-        # deadlock will be killed afer 20 secs
-        signal.signal(signal.SIGALRM, self.my_signal_handler)
-        signal.alarm(20)
+        # set the signal handler for deadlock
+        self.sig_handler = SignalHandler(self.fail)
         self.base = BaseModules()
         self.stats_server = ThreadingServerManager(MyStats)
         self.stats_server.run()
@@ -327,9 +326,8 @@ class TestStatsHttpd(unittest.TestCase):
             self.stats_httpd.stop()
         self.stats_server.shutdown()
         self.base.shutdown()
-
-    def my_signal_handler(self, signal, frame):
-        self.fail("A deadlock might be detected")
+        # reset the signal handler
+        self.sig_handler.reset()
 
     def test_init(self):
         server_address = get_availaddr()
@@ -392,23 +390,13 @@ class TestStatsHttpd(unittest.TestCase):
                 self.assertEqual(ht.address_family, socket.AF_INET6)
                 self.assertTrue(isinstance(ht.socket, socket.socket))
 
-        # dual stack (address is ipv4)
-        if self.ipv6_enabled:
-            server_addresses = get_availaddr()
-            self.stats_httpd = MyStatsHttpd(server_addresses)
-            for ht in self.stats_httpd.httpd:
-                self.assertTrue(isinstance(ht, stats_httpd.HttpServer))
-                self.assertEqual(ht.address_family, socket.AF_INET)
-                self.assertTrue(isinstance(ht.socket, socket.socket))
-
-        # only-ipv4 single stack
-        if not self.ipv6_enabled:
-            server_addresses = get_availaddr()
-            self.stats_httpd = MyStatsHttpd(server_addresses)
-            for ht in self.stats_httpd.httpd:
-                self.assertTrue(isinstance(ht, stats_httpd.HttpServer))
-                self.assertEqual(ht.address_family, socket.AF_INET)
-                self.assertTrue(isinstance(ht.socket, socket.socket))
+        # dual/single stack (address is ipv4)
+        server_addresses = get_availaddr()
+        self.stats_httpd = MyStatsHttpd(server_addresses)
+        for ht in self.stats_httpd.httpd:
+            self.assertTrue(isinstance(ht, stats_httpd.HttpServer))
+            self.assertEqual(ht.address_family, socket.AF_INET)
+            self.assertTrue(isinstance(ht.socket, socket.socket))
 
         # any address (IPv4)
         server_addresses = get_availaddr(address='0.0.0.0')
@@ -467,7 +455,9 @@ class TestStatsHttpd(unittest.TestCase):
         self.stats_httpd.cc_session.close()
         self.assertRaises(ValueError, self.stats_httpd.start)
 
-    def test_select_failure1(self):
+    def test_failure_with_a_select_error (self):
+        """checks select.error is raised if the exception except
+        errno.EINTR is raised while it's selecting"""
         def raise_select_except(*args):
             raise select.error('dummy error')
         orig_select = stats_httpd.select.select
@@ -476,7 +466,9 @@ class TestStatsHttpd(unittest.TestCase):
         self.assertRaises(select.error, self.stats_httpd.start)
         stats_httpd.select.select = orig_select
 
-    def test_select_failure2(self):
+    def test_nofailure_with_errno_EINTR(self):
+        """checks no exception is raised if errno.EINTR is raised
+        while it's selecting"""
         def raise_select_except(*args):
             raise select.error(errno.EINTR)
         orig_select = stats_httpd.select.select
diff --git a/src/bin/stats/tests/b10-stats_test.py b/src/bin/stats/tests/b10-stats_test.py
index 5982595..3813c7e 100644
--- a/src/bin/stats/tests/b10-stats_test.py
+++ b/src/bin/stats/tests/b10-stats_test.py
@@ -27,11 +27,10 @@ import threading
 import io
 import time
 import imp
-import signal
 
 import stats
 import isc.cc.session
-from test_utils import BaseModules, ThreadingServerManager, MyStats, send_command, send_shutdown
+from test_utils import BaseModules, ThreadingServerManager, MyStats, SignalHandler, send_command, send_shutdown
 
 class TestUtilties(unittest.TestCase):
     items = [
@@ -147,9 +146,8 @@ class TestCallback(unittest.TestCase):
 
 class TestStats(unittest.TestCase):
     def setUp(self):
-        # deadlock will be killed afer 20 secs
-        signal.signal(signal.SIGALRM, self.my_signal_handler)
-        signal.alarm(20)
+        # set the signal handler for deadlock
+        self.sig_handler = SignalHandler(self.fail)
         self.base = BaseModules()
         self.stats = stats.Stats()
         self.const_timestamp = 1308730448.965706
@@ -158,9 +156,8 @@ class TestStats(unittest.TestCase):
 
     def tearDown(self):
         self.base.shutdown()
-
-    def my_signal_handler(self, signal, frame):
-        self.fail("A deadlock might be detected")
+        # reset the signal handler
+        self.sig_handler.reset()
 
     def test_init(self):
         self.assertEqual(self.stats.module_name, 'Stats')
diff --git a/src/bin/stats/tests/test_utils.py b/src/bin/stats/tests/test_utils.py
index 1eaf220..3cd394f 100644
--- a/src/bin/stats/tests/test_utils.py
+++ b/src/bin/stats/tests/test_utils.py
@@ -9,6 +9,7 @@ import sys
 import threading
 import tempfile
 import json
+import signal
 
 import msgq
 import isc.config.cfgmgr
@@ -19,6 +20,24 @@ import stats_httpd
 if 'BIND10_MSGQ_SOCKET_FILE' not in os.environ:
     os.environ['BIND10_MSGQ_SOCKET_FILE'] = tempfile.mktemp(prefix='msgq_socket_')
 
+class SignalHandler():
+    """A signal handler class for deadlock in unittest"""
+    def __init__(self, fail_handler, timeout=20):
+        """sets a schedule in SIGARM for invoking the handler via
+        unittest.TestCase after timeout seconds (default is 20)"""
+        self.fail_handler = fail_handler
+        self.orig_handler = signal.signal(signal.SIGALRM, self.sig_handler)
+        signal.alarm(timeout)
+
+    def reset(self):
+        """resets the schedule in SIGALRM"""
+        signal.alarm(0)
+        signal.signal(signal.SIGALRM, self.orig_handler)
+
+    def sig_handler(self, signal, frame):
+        """envokes unittest.TestCase.fail as a signal handler"""
+        self.fail_handler("A deadlock might be detected")
+
 def send_command(command_name, module_name, params=None, session=None, nonblock=False, timeout=None):
     if session is not None:
         cc_session = session
@@ -47,6 +66,9 @@ def send_shutdown(module_name, **kwargs):
 class ThreadingServerManager:
     def __init__(self, server, *args, **kwargs):
         self.server = None
+        # retrying to create a server object until 3 times because a
+        # SessionTimeout depending on some environment or timing may
+        # be accidentally raised
         n = 0
         while True:
             try:
@@ -54,7 +76,6 @@ class ThreadingServerManager:
             except isc.cc.session.SessionTimeout:
                 if self.server is not None:
                     self.server.shutdown()
-                # retrying until 3 times
                 if n >2: raise
                 n = n + 1
                 continue




More information about the bind10-changes mailing list