[tor-commits] [stem/master] Speed up auth's test_all_use_cases unit test

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


commit 9fa91542525e021ea11f7889293fae35d85a7f8c
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Jan 5 10:43:01 2017 -0800

    Speed up auth's test_all_use_cases unit test
    
    This test isn't overly burdensome and it's neat that it tests all combinations,
    but this one unit test alone takes around as much as every other test put
    together.
    
    We can speed it up without losing coverage by having it raise some parent
    exceptions rather than each child exception individually. On my 'lil netbook
    this drops the test runtime from 5s to 1s (80% faster).
---
 test/unit/connection/authentication.py | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/test/unit/connection/authentication.py b/test/unit/connection/authentication.py
index b12efeb..70de6d7 100644
--- a/test/unit/connection/authentication.py
+++ b/test/unit/connection/authentication.py
@@ -65,35 +65,25 @@ class TestAuthenticate(unittest.TestCase):
 
     # exceptions that the authentication functions are documented to raise
 
-    all_auth_none_exc = (None, stem.connection.OpenAuthRejected(None))
+    all_auth_none_exc = (
+      None,
+      stem.connection.OpenAuthRejected(None),
+      stem.ControllerError(None))
 
     all_auth_password_exc = (
       None,
       stem.connection.PasswordAuthRejected(None),
-      stem.connection.IncorrectPassword(None))
+      stem.connection.IncorrectPassword(None),
+      stem.ControllerError(None))
 
     all_auth_cookie_exc = (
       None,
-      stem.connection.IncorrectCookieSize(None, False, None),
-      stem.connection.UnreadableCookieFile(None, False, None),
       stem.connection.CookieAuthRejected(None, False, None),
       stem.connection.IncorrectCookieValue(None, False, None),
-      stem.connection.UnrecognizedAuthChallengeMethod(None, None, None),
+      stem.connection.IncorrectCookieSize(None, False, None),
+      stem.connection.UnreadableCookieFile(None, False, None),
       stem.connection.AuthChallengeFailed(None, None),
-      stem.connection.AuthSecurityFailure(None, None),
-      stem.connection.InvalidClientNonce(None, None))
-
-    # authentication functions might raise a controller error when
-    # 'suppress_ctl_errors' is False, so including those
-
-    control_exc = (
-      stem.ProtocolError(None),
-      stem.SocketError(None),
-      stem.SocketClosed(None))
-
-    all_auth_none_exc += control_exc
-    all_auth_password_exc += control_exc
-    all_auth_cookie_exc += control_exc
+      stem.ControllerError(None))
 
     auth_method_combinations = mocking.get_all_combinations([
       stem.connection.AuthMethod.NONE,





More information about the tor-commits mailing list