Swap out bcrypt for md5 in tests

This reduces our ~8 second sequential test time down to ~7 seconds
This commit is contained in:
Daniel Wagner-Hall 2015-08-26 15:59:32 +01:00
parent 4c56928263
commit 3063383547
3 changed files with 39 additions and 3 deletions

View file

@ -27,6 +27,7 @@ from twisted.enterprise.adbapi import ConnectionPool
from collections import namedtuple
from mock import patch, Mock
import hashlib
import urllib
import urlparse
@ -67,6 +68,18 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs):
**kargs
)
# bcrypt is far too slow to be doing in unit tests
def swap_out_hash_for_testing(old_build_handlers):
def build_handlers():
handlers = old_build_handlers()
auth_handler = handlers.auth_handler
auth_handler.hash = lambda p: hashlib.md5(p).hexdigest()
auth_handler.validate_hash = lambda p, h: hashlib.md5(p).hexdigest() == h
return handlers
return build_handlers
hs.build_handlers = swap_out_hash_for_testing(hs.build_handlers)
defer.returnValue(hs)