fix tests

This commit is contained in:
Rodolphe Marques 2017-04-03 14:29:31 +02:00 committed by vrde
parent 96daa98699
commit 83a7cffc3f
No known key found for this signature in database
GPG Key ID: 6581C7C39B3D397D
3 changed files with 24 additions and 19 deletions

View File

@ -23,8 +23,10 @@ logger_results = logging.getLogger('pipeline.election.results')
class Election:
"""Election class."""
def __init__(self, events_queue):
def __init__(self, events_queue=None):
self.bigchain = Bigchain()
self.event_handler = None
if events_queue:
self.event_handler = EventHandler(events_queue)
def check_for_quorum(self, next_vote):
@ -71,6 +73,7 @@ class Election:
return invalid_block
def handle_block_events(self, result, block_id):
if self.event_handler:
if result['status'] == self.bigchain.BLOCK_UNDECIDED:
return
elif result['status'] == self.bigchain.BLOCK_INVALID:
@ -82,8 +85,8 @@ class Election:
self.event_handler.put_event(event)
def create_pipeline(events_queue):
election = Election(events_queue)
def create_pipeline(events_queue=None):
election = Election(events_queue=events_queue)
election_pipeline = Pipeline([
Node(election.check_for_quorum),
@ -98,8 +101,8 @@ def get_changefeed():
return backend.get_changefeed(connection, 'votes', ChangeFeed.INSERT)
def start(events_queue):
pipeline = create_pipeline(events_queue)
def start(events_queue=None):
pipeline = create_pipeline(events_queue=events_queue)
pipeline.setup(indata=get_changefeed())
pipeline.start()
return pipeline

View File

@ -45,7 +45,7 @@ def start():
stale.start()
logger.info('Starting election')
election.start(events_queue)
election.start(events_queue=events_queue)
# start the web api
app_server = server.create_server(bigchaindb.config['server'])

View File

@ -1,6 +1,6 @@
from unittest.mock import patch
from multiprocessing import Process
from multiprocessing import Process, Queue
from bigchaindb.pipelines import vote, block, election, stale
@ -9,14 +9,16 @@ from bigchaindb.pipelines import vote, block, election, stale
@patch.object(block, 'start')
@patch.object(vote, 'start')
@patch.object(Process, 'start')
def test_processes_start(mock_vote, mock_block, mock_election, mock_stale,
mock_process):
def test_processes_start(mock_process, mock_vote, mock_block, mock_election,
mock_stale):
from bigchaindb import processes
processes.start()
mock_vote.assert_called_with()
mock_block.assert_called_with()
mock_election.assert_called_with()
mock_stale.assert_called_with()
mock_process.assert_called_with()
assert mock_election.call_count == 1
# the events queue is declared inside processes.start()
assert type(mock_election.call_args[1]['events_queue']) == type(Queue())