def test_empty_pool_is_populated_with_instances(mock_queue): from bigchaindb import util pool = util.pool(lambda: 'hello', 4) assert len(mock_queue.items) == 0 with pool() as instance: assert instance == 'hello' assert len(mock_queue.items) == 1 with pool() as instance: assert instance == 'hello' assert len(mock_queue.items) == 2 with pool() as instance: assert instance == 'hello' assert len(mock_queue.items) == 3 with pool() as instance: assert instance == 'hello' assert len(mock_queue.items) == 4 with pool() as instance: assert instance == 'hello' assert len(mock_queue.items) == 4
def test_pool_raises_empty_exception_when_timeout(mock_queue): from bigchaindb import util pool = util.pool(lambda: 'hello', 1, timeout=1) assert len(mock_queue.items) == 0 with pool() as instance: assert instance == 'hello' assert len(mock_queue.items) == 1 # take the only resource available assert pool().__enter__() == 'hello' with pytest.raises(queue.Empty): with pool() as instance: assert instance == 'hello'
def create_app(settings): """Return an instance of the Flask application. Args: debug (bool): a flag to activate the debug mode for the app (default: False). """ app = Flask(__name__) app.debug = settings.get('debug', False) app.config['bigchain_pool'] = util.pool(Bigchain, size=settings.get('threads', 4)) app.config['monitor'] = Monitor() app.register_blueprint(views.basic_views, url_prefix='/api/v1') return app
def create_app(settings): """Return an instance of the Flask application. Args: debug (bool): a flag to activate the debug mode for the app (default: False). """ app = Flask(__name__) app.debug = settings.get('debug', False) app.config['bigchain_pool'] = util.pool(Bigchain, size=settings.get('threads', 4)) app.config['monitor'] = Monitor() app.register_blueprint(info_views, url_prefix='/') app.register_blueprint(transaction_views, url_prefix='/api/v1') return app
def create_app(*, debug=False, threads=4): """Return an instance of the Flask application. Args: debug (bool): a flag to activate the debug mode for the app (default: False). threads (int): number of threads to use Return: an instance of the Flask application. """ app = Flask(__name__) app.debug = debug app.config['bigchain_pool'] = util.pool(Bigchain, size=threads) app.config['monitor'] = Monitor() app.register_blueprint(info_views, url_prefix='/') app.register_blueprint(transaction_views, url_prefix='/api/v1') return app
def create_app(settings): """Return an instance of the Flask application. Args: debug (bool): a flag to activate the debug mode for the app (default: False). """ app = Flask(__name__) app.debug = settings.get('debug', False) app.config['bigchain_pool'] = util.pool(Bigchain, size=settings.get('threads', 4)) app.config['monitor'] = Monitor() #welcome view app.register_blueprint(info_views, url_prefix='/') #transaction operate view app.register_blueprint(transaction_views, url_prefix='/uniledger/v1/transaction') #block operate view app.register_blueprint(block_views, url_prefix='/uniledger/v1/block') #vote operate view app.register_blueprint(vote_views, url_prefix='/uniledger/v1/vote') #timestat operate view app.register_blueprint(timestat_views, url_prefix='/uniledger/v1/timestat') app.register_blueprint(condition_views, url_prefix='/uniledger/v1/condition') app.register_blueprint(contract_views, url_prefix='/uniledger/v1/contract') app.register_blueprint(bordertrade_views, url_prefix='/uniledger/v1/bordertrade') app.register_blueprint(acount_views, url_prefix='/uniledger/v1/account') return app
def test_pool_blocks_if_no_instances_available(mock_queue): from bigchaindb import util pool = util.pool(lambda: 'hello', 4) assert len(mock_queue.items) == 0 # We need to manually trigger the `__enter__` method so the context # manager will "hang" and not return the resource to the pool assert pool().__enter__() == 'hello' assert len(mock_queue.items) == 0 assert pool().__enter__() == 'hello' assert len(mock_queue.items) == 0 assert pool().__enter__() == 'hello' assert len(mock_queue.items) == 0 # We need to keep a reference of the last context manager so we can # manually release the resource last = pool() assert last.__enter__() == 'hello' assert len(mock_queue.items) == 0 # This would block using `queue.Queue` but since we mocked it it will # just raise a IndexError because it's trying to pop from an empty list. with pytest.raises(IndexError): assert pool().__enter__() == 'hello' assert len(mock_queue.items) == 0 # Release the last resource last.__exit__(None, None, None) assert len(mock_queue.items) == 1 assert pool().__enter__() == 'hello' assert len(mock_queue.items) == 0