mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
fix tests
This commit is contained in:
parent
96daa98699
commit
83a7cffc3f
@ -23,8 +23,10 @@ logger_results = logging.getLogger('pipeline.election.results')
|
|||||||
class Election:
|
class Election:
|
||||||
"""Election class."""
|
"""Election class."""
|
||||||
|
|
||||||
def __init__(self, events_queue):
|
def __init__(self, events_queue=None):
|
||||||
self.bigchain = Bigchain()
|
self.bigchain = Bigchain()
|
||||||
|
self.event_handler = None
|
||||||
|
if events_queue:
|
||||||
self.event_handler = EventHandler(events_queue)
|
self.event_handler = EventHandler(events_queue)
|
||||||
|
|
||||||
def check_for_quorum(self, next_vote):
|
def check_for_quorum(self, next_vote):
|
||||||
@ -71,6 +73,7 @@ class Election:
|
|||||||
return invalid_block
|
return invalid_block
|
||||||
|
|
||||||
def handle_block_events(self, result, block_id):
|
def handle_block_events(self, result, block_id):
|
||||||
|
if self.event_handler:
|
||||||
if result['status'] == self.bigchain.BLOCK_UNDECIDED:
|
if result['status'] == self.bigchain.BLOCK_UNDECIDED:
|
||||||
return
|
return
|
||||||
elif result['status'] == self.bigchain.BLOCK_INVALID:
|
elif result['status'] == self.bigchain.BLOCK_INVALID:
|
||||||
@ -82,8 +85,8 @@ class Election:
|
|||||||
self.event_handler.put_event(event)
|
self.event_handler.put_event(event)
|
||||||
|
|
||||||
|
|
||||||
def create_pipeline(events_queue):
|
def create_pipeline(events_queue=None):
|
||||||
election = Election(events_queue)
|
election = Election(events_queue=events_queue)
|
||||||
|
|
||||||
election_pipeline = Pipeline([
|
election_pipeline = Pipeline([
|
||||||
Node(election.check_for_quorum),
|
Node(election.check_for_quorum),
|
||||||
@ -98,8 +101,8 @@ def get_changefeed():
|
|||||||
return backend.get_changefeed(connection, 'votes', ChangeFeed.INSERT)
|
return backend.get_changefeed(connection, 'votes', ChangeFeed.INSERT)
|
||||||
|
|
||||||
|
|
||||||
def start(events_queue):
|
def start(events_queue=None):
|
||||||
pipeline = create_pipeline(events_queue)
|
pipeline = create_pipeline(events_queue=events_queue)
|
||||||
pipeline.setup(indata=get_changefeed())
|
pipeline.setup(indata=get_changefeed())
|
||||||
pipeline.start()
|
pipeline.start()
|
||||||
return pipeline
|
return pipeline
|
||||||
|
@ -45,7 +45,7 @@ def start():
|
|||||||
stale.start()
|
stale.start()
|
||||||
|
|
||||||
logger.info('Starting election')
|
logger.info('Starting election')
|
||||||
election.start(events_queue)
|
election.start(events_queue=events_queue)
|
||||||
|
|
||||||
# start the web api
|
# start the web api
|
||||||
app_server = server.create_server(bigchaindb.config['server'])
|
app_server = server.create_server(bigchaindb.config['server'])
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process, Queue
|
||||||
from bigchaindb.pipelines import vote, block, election, stale
|
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(block, 'start')
|
||||||
@patch.object(vote, 'start')
|
@patch.object(vote, 'start')
|
||||||
@patch.object(Process, 'start')
|
@patch.object(Process, 'start')
|
||||||
def test_processes_start(mock_vote, mock_block, mock_election, mock_stale,
|
def test_processes_start(mock_process, mock_vote, mock_block, mock_election,
|
||||||
mock_process):
|
mock_stale):
|
||||||
from bigchaindb import processes
|
from bigchaindb import processes
|
||||||
|
|
||||||
processes.start()
|
processes.start()
|
||||||
|
|
||||||
mock_vote.assert_called_with()
|
mock_vote.assert_called_with()
|
||||||
mock_block.assert_called_with()
|
mock_block.assert_called_with()
|
||||||
mock_election.assert_called_with()
|
|
||||||
mock_stale.assert_called_with()
|
mock_stale.assert_called_with()
|
||||||
mock_process.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())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user