Problem: ABCI server not run for tests (#2138)

Solution: Create seperate test mark for which the ABCI server will be running
This commit is contained in:
Vanshdeep Singh 2018-04-10 17:29:25 +02:00 committed by vrde
parent 6f69f39ff4
commit 7f6782e31d
8 changed files with 92 additions and 8 deletions

9
.ci/entrypoint.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
set -e -x
if [[ ${BIGCHAINDB_CI_ABCI} == 'enable' ]]; then
sleep 3600
else
bigchaindb start
fi

View File

@ -6,6 +6,8 @@ pip install --upgrade pip
if [[ -n ${TOXENV} ]]; then
pip install --upgrade tox
elif [[ ${BIGCHAINDB_CI_ABCI} == 'enable' ]]; then
docker-compose build --no-cache --build-arg abci_status=enable bigchaindb
elif [[ $TRAVIS_PYTHON_VERSION == 3.5 ]]; then
docker-compose build --build-arg python_version=3.5 --no-cache bigchaindb
pip install --upgrade codecov

View File

@ -4,6 +4,8 @@ set -e -x
if [[ -n ${TOXENV} ]]; then
tox -e ${TOXENV}
elif [[ ${BIGCHAINDB_CI_ABCI} == 'enable' ]]; then
docker-compose exec bigchaindb pytest -v -m abci
else
docker-compose run --rm --no-deps bigchaindb pytest -v --cov=bigchaindb
docker-compose exec bigchaindb pytest -v --cov=bigchaindb
fi

View File

@ -38,6 +38,11 @@ matrix:
env:
- BIGCHAINDB_DATABASE_BACKEND=localmongodb
- BIGCHAINDB_DATABASE_SSL=
- python: 3.6
env:
- BIGCHAINDB_DATABASE_BACKEND=localmongodb
- BIGCHAINDB_DATABASE_SSL=
- BIGCHAINDB_CI_ABCI=enable
before_install: sudo .ci/travis-before-install.sh

View File

@ -10,6 +10,7 @@ RUN apt-get update \
&& apt-get clean
ARG backend
ARG abci_status
# When developing with Python in a docker container, we are using PYTHONBUFFERED
# to force stdin, stdout and stderr to be totally unbuffered and to capture logs/outputs
@ -26,6 +27,8 @@ ENV BIGCHAINDB_WSSERVER_ADVERTISED_SCHEME ws
ENV BIGCHAINDB_TENDERMINT_PORT 46657
ENV BIGCHAINDB_CI_ABCI abci_status
RUN mkdir -p /usr/src/app
COPY . /usr/src/app/
WORKDIR /usr/src/app

View File

@ -43,7 +43,7 @@ services:
interval: 3s
timeout: 5s
retries: 3
command: bigchaindb start
entrypoint: '.ci/entrypoint.sh'
tendermint:
image: tendermint/tendermint:0.12
volumes:

View File

@ -555,6 +555,52 @@ def mocked_setup_sub_logger(mocker):
'bigchaindb.log.setup.setup_sub_logger', autospec=True, spec_set=True)
@pytest.fixture(autouse=True)
def _abci_http(request):
if request.keywords.get('abci', None):
request.getfixturevalue('abci_http')
@pytest.fixture
def abci_http(abci_server, tendermint_host, tendermint_port):
import requests
import time
for i in range(5):
try:
uri = 'http://{}:{}/abci_info'.format(tendermint_host, tendermint_port)
requests.get(uri)
return True
except requests.exceptions.RequestException as e:
pass
time.sleep(1)
return False
@pytest.yield_fixture(scope='session')
def event_loop(request):
import asyncio
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()
@pytest.mark.bdb
@pytest.fixture(scope='session')
def abci_server():
from abci import ABCIServer
from bigchaindb.tendermint.core import App
from bigchaindb.utils import Process
app = ABCIServer(app=App())
abci_proxy = Process(name='ABCI', target=app.run)
yield abci_proxy.start()
abci_proxy.terminate()
@pytest.fixture(scope='session')
def certs_dir():
return os.path.abspath('tests/backend/mongodb-ssl/certs')

View File

@ -1,13 +1,12 @@
import json
import base64
from queue import Queue
from aiohttp import ClientSession
import pytest
pytestmark = pytest.mark.tendermint
@pytest.mark.tendermint
def test_process_event_new_block():
from bigchaindb.tendermint.event_stream import process_event
@ -39,6 +38,7 @@ def test_process_event_new_block():
assert isinstance(block.data['height'], int)
@pytest.mark.tendermint
def test_process_event_empty_block():
from bigchaindb.tendermint.event_stream import process_event
@ -57,6 +57,7 @@ def test_process_event_empty_block():
assert event_queue.empty()
@pytest.mark.tendermint
def test_process_unknown_event():
from bigchaindb.tendermint.event_stream import process_event
@ -68,10 +69,13 @@ def test_process_unknown_event():
assert event_queue.empty()
@pytest.mark.skip('This test will be an integration test.')
@pytest.mark.abci
@pytest.mark.asyncio
async def test_subscribe_events(tendermint_ws_url):
async def test_subscribe_events(tendermint_ws_url, b):
from bigchaindb.tendermint.event_stream import subscribe_events
from bigchaindb.common.crypto import generate_key_pair
from bigchaindb.models import Transaction
session = ClientSession()
ws = await session.ws_connect(tendermint_ws_url)
stream_id = 'bigchaindb_stream_01'
@ -82,4 +86,17 @@ async def test_subscribe_events(tendermint_ws_url):
assert msg_data_dict['id'] == stream_id
assert msg_data_dict['jsonrpc'] == '2.0'
assert msg_data_dict['result'] == {}
# TODO What else should be there? Right now, getting error.
alice = generate_key_pair()
tx = Transaction.create([alice.public_key],
[([alice.public_key], 1)],
asset=None)\
.sign([alice.private_key])
b.post_transaction(tx, 'broadcast_tx_async')
msg = await ws.receive()
msg_data_dict = json.loads(msg.data)
raw_txn = msg_data_dict['result']['data']['data']['block']['data']['txs'][0]
transaction = json.loads(base64.b64decode(raw_txn).decode('utf8'))
assert transaction == tx.to_dict()