[tor-commits] [stem/master] Include test runtime in verbose test output

atagar at torproject.org atagar at torproject.org
Mon Jan 30 18:31:26 UTC 2017


commit a1f241a45952ae2c2e9b7963d0c7658c80e78755
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Jan 4 10:45:07 2017 -0800

    Include test runtime in verbose test output
    
    When running our tests with a --verbose flag including individual test
    runtimes. This'll greatly help us when investigating test performance.
    
    Also shortening a few test names so output aligns better.
---
 run_tests.py                     |  1 +
 test/integ/control/controller.py |  2 +-
 test/integ/descriptor/remote.py  |  4 ++--
 test/integ/util/connection.py    | 18 +++++++++---------
 test/output.py                   | 28 ++++++++++++++++++++++++++++
 test/unit/control/controller.py  |  2 +-
 6 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index df4da12..2d31a1b 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -177,6 +177,7 @@ def main():
 
   output_filters = (
     error_tracker.get_filter(),
+    test.output.runtimes,
     test.output.strip_module,
     test.output.align_results,
     test.output.colorize,
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index c249c08..1c80ae2 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -690,7 +690,7 @@ class TestController(unittest.TestCase):
 
   @require_controller
   @require_version(Requirement.ADD_ONION_BASIC_AUTH)
-  def test_with_ephemeral_hidden_services_basic_auth_without_credentials(self):
+  def test_with_ephemeral_hidden_services_basic_auth_no_credentials(self):
     """
     Exercises creating ephemeral hidden services when attempting to use basic
     auth but not including any credentials.
diff --git a/test/integ/descriptor/remote.py b/test/integ/descriptor/remote.py
index 098041d..889f3d8 100644
--- a/test/integ/descriptor/remote.py
+++ b/test/integ/descriptor/remote.py
@@ -184,7 +184,7 @@ class TestDescriptorDownloader(unittest.TestCase):
 
   @require_online
   @only_run_once
-  def test_get_consensus_for_microdescriptors(self):
+  def test_get_microdescriptor_consensus(self):
     """
     Exercises the downloader's get_consensus() method for fetching a
     microdescriptor consensus.
@@ -239,7 +239,7 @@ class TestDescriptorDownloader(unittest.TestCase):
       self.fail("Stem's cached fallback directories are out of date. Please run 'cache_fallback_directories.py'...\n\n%s" % stem.descriptor.remote._fallback_directory_differences(cached_fallback_directories, latest_fallback_directories))
 
   @require_online
-  def test_that_fallback_directories_are_reachable(self):
+  def test_fallback_directory_reachability(self):
     """
     Fetch information from each fallback directory to confirm that it's
     available.
diff --git a/test/integ/util/connection.py b/test/integ/util/connection.py
index 64653d1..c6ca04a 100644
--- a/test/integ/util/connection.py
+++ b/test/integ/util/connection.py
@@ -18,7 +18,7 @@ class TestConnection(unittest.TestCase):
       test.runner.skip(self, '(no control port)')
       return
     elif not runner.is_ptraceable():
-      test.runner.skip(self, '(DisableDebuggerAttachment is set)')
+      test.runner.skip(self, '(DisableDebuggerAttachment set)')
       return
     elif resolver not in system_resolvers():
       test.runner.skip(self, '(resolver unavailable on this platform)')
@@ -33,28 +33,28 @@ class TestConnection(unittest.TestCase):
 
       self.fail('Unable to find localhost connection with %s:\n%s' % (resolver, '\n'.join(connections)))
 
-  def test_get_connections_by_proc(self):
+  def test_connections_by_proc(self):
     self.check_resolver(Resolver.PROC)
 
-  def test_get_connections_by_netstat(self):
+  def test_connections_by_netstat(self):
     self.check_resolver(Resolver.NETSTAT)
 
-  def test_get_connections_by_windows_netstat(self):
+  def test_connections_by_windows_netstat(self):
     self.check_resolver(Resolver.NETSTAT_WINDOWS)
 
-  def test_get_connections_by_ss(self):
+  def test_connections_by_ss(self):
     self.check_resolver(Resolver.SS)
 
-  def test_get_connections_by_lsof(self):
+  def test_connections_by_lsof(self):
     self.check_resolver(Resolver.LSOF)
 
-  def test_get_connections_by_sockstat(self):
+  def test_connections_by_sockstat(self):
     self.check_resolver(Resolver.SOCKSTAT)
 
-  def test_get_connections_by_bsd_sockstat(self):
+  def test_connections_by_bsd_sockstat(self):
     self.check_resolver(Resolver.BSD_SOCKSTAT)
 
-  def test_get_connections_by_bsd_procstat(self):
+  def test_connections_by_bsd_procstat(self):
     self.check_resolver(Resolver.BSD_PROCSTAT)
 
   def test_that_we_are_checking_all_resolvers(self):
diff --git a/test/output.py b/test/output.py
index bff719a..c9a2116 100644
--- a/test/output.py
+++ b/test/output.py
@@ -10,6 +10,7 @@ import re
 import sys
 
 import stem.util.enum
+import stem.util.test_tools
 
 from stem.util import system, term
 
@@ -154,6 +155,27 @@ def strip_module(line_type, line_content):
   return line_content
 
 
+def runtimes(line_type, line_content):
+  """
+  Provides test runtimes if showing verbose results.
+  """
+
+  m = re.search('(test\.[^)]*)', line_content)
+
+  if m and line_type == LineType.OK:
+    test = '%s.%s' % (m.group(0), line_content.split()[0])
+    runtime = stem.util.test_tools.test_runtimes().get(test)
+
+    if runtime is None:
+      pass
+    if runtime >= 1.0:
+      line_content = '%s (%0.2fs)' % (line_content, runtime)
+    else:
+      line_content = '%s (%i ms)' % (line_content, runtime * 1000)
+
+  return line_content
+
+
 def align_results(line_type, line_content):
   """
   Strips the normal test results, and adds a right aligned variant instead with
@@ -169,6 +191,12 @@ def align_results(line_type, line_content):
       line_content = line_content.replace(ending, '', 1)
       break
 
+  # right align runtimes
+
+  if line_content.endswith('s)'):
+    div = line_content.rfind(' (')
+    line_content = '%-53s%6s  ' % (line_content[:div], line_content[div + 2:-1])
+
   # skipped tests have extra single quotes around the reason
   if line_type == LineType.SKIPPED:
     line_content = line_content.replace("'(", "(", 1).replace(")'", ")", 1)
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index fedb86a..0c82a94 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -462,7 +462,7 @@ class TestControl(unittest.TestCase):
     self.assertEqual(stem.descriptor.router_status_entry.RouterStatusEntryV3(desc), self.controller.get_network_status())
 
   @patch('stem.control.Controller.get_info')
-  def test_get_network_status_when_raising_descriptor_unavailable(self, get_info_mock):
+  def test_get_network_status_when_unavailable(self, get_info_mock):
     """
     Exercises the get_network_status() method.
     """





More information about the tor-commits mailing list