Add lru_cache to load_consensus_plugin

This commit is contained in:
vrde 2016-05-11 16:18:52 +02:00
parent fa26113e98
commit ee2fa053d9
No known key found for this signature in database
GPG Key ID: 6581C7C39B3D397D
3 changed files with 10 additions and 1 deletions

View File

@ -16,6 +16,7 @@ import copy
import json
import logging
import collections
from functools import lru_cache
from pkg_resources import iter_entry_points, ResolutionError
@ -218,6 +219,7 @@ def autoconfigure(filename=None, config=None, force=False):
set_config(newconfig) # sets bigchaindb.config
@lru_cache()
def load_consensus_plugin(name=None):
"""Find and load the chosen consensus plugin.

View File

@ -19,3 +19,7 @@ def speedtest_validate_transaction():
b.validate_transaction(tx_signed)
profiler.print_stats()
if __name__ == '__main__':
speedtest_validate_transaction()

View File

@ -58,12 +58,15 @@ def test_load_consensus_plugin_raises_with_invalid_subclass(monkeypatch):
# Monkeypatch entry_point.load to return something other than a
# ConsensusRules instance
from bigchaindb import config_utils
import time
monkeypatch.setattr(config_utils,
'iter_entry_points',
lambda *args: [type('entry_point', (object), {'load': lambda: object})])
with pytest.raises(TypeError):
config_utils.load_consensus_plugin()
# Since the function is decorated with `lru_cache`, we need to
# "miss" the cache using a name that has not been used previously
config_utils.load_consensus_plugin(str(time.time()))
def test_map_leafs_iterator():