diff --git a/bigchaindb/config_utils.py b/bigchaindb/config_utils.py index dc396522..c9da67b1 100644 --- a/bigchaindb/config_utils.py +++ b/bigchaindb/config_utils.py @@ -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. diff --git a/speed-tests/speed_tests.py b/speed-tests/speed_tests.py index 6fb67714..b6a6b016 100644 --- a/speed-tests/speed_tests.py +++ b/speed-tests/speed_tests.py @@ -19,3 +19,7 @@ def speedtest_validate_transaction(): b.validate_transaction(tx_signed) profiler.print_stats() + + +if __name__ == '__main__': + speedtest_validate_transaction() diff --git a/tests/utils/test_config_utils.py b/tests/utils/test_config_utils.py index 0a365102..29aa5d0b 100644 --- a/tests/utils/test_config_utils.py +++ b/tests/utils/test_config_utils.py @@ -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():