Browse Source

[2689] fake socket.gethostbyaddr() to avoid unexpected blocking

JINMEI Tatuya 12 years ago
parent
commit
5adf1f39d4
1 changed files with 8 additions and 0 deletions
  1. 8 0
      src/bin/stats/tests/b10-stats-httpd_test.py

+ 8 - 0
src/bin/stats/tests/b10-stats-httpd_test.py

@@ -609,8 +609,16 @@ class TestStatsHttpd(unittest.TestCase):
         self.stats_server.run()
         self.stats_server.run()
         # checking IPv6 enabled on this platform
         # checking IPv6 enabled on this platform
         self.ipv6_enabled = is_ipv6_enabled()
         self.ipv6_enabled = is_ipv6_enabled()
+        # instantiation of StatsHttpd indirectly calls gethostbyaddr(), which
+        # can block for an uncontrollable period, leading many undesirable
+        # results.  We should rather eliminate the reliance, but until we
+        # can make such fundamental cleanup we replace it with a faked method;
+        # in our test scenario the return value doesn't matter.
+        self.__gethostbyaddr_orig = socket.gethostbyaddr
+        socket.gethostbyaddr = lambda x: ('test.example.', [], None)
 
 
     def tearDown(self):
     def tearDown(self):
+        socket.gethostbyaddr = self.__gethostbyaddr_orig
         if hasattr(self, "stats_httpd"):
         if hasattr(self, "stats_httpd"):
             self.stats_httpd.stop()
             self.stats_httpd.stop()
         self.stats_server.shutdown()
         self.stats_server.shutdown()