mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Remove unused code
This commit is contained in:
parent
b8e6b0b830
commit
b9fba73c14
@ -156,7 +156,7 @@ def run_start(args):
|
|||||||
|
|
||||||
if args.start_rethinkdb:
|
if args.start_rethinkdb:
|
||||||
try:
|
try:
|
||||||
proc, port = utils.start_rethinkdb()
|
proc = utils.start_rethinkdb()
|
||||||
except StartupError as e:
|
except StartupError as e:
|
||||||
sys.exit('Error starting RethinkDB, reason is: {}'.format(e))
|
sys.exit('Error starting RethinkDB, reason is: {}'.format(e))
|
||||||
logger.info('RethinkDB started with PID %s' % proc.pid)
|
logger.info('RethinkDB started with PID %s' % proc.pid)
|
||||||
|
@ -5,7 +5,6 @@ for ``argparse.ArgumentParser``.
|
|||||||
import argparse
|
import argparse
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
|
||||||
|
|
||||||
import rethinkdb as r
|
import rethinkdb as r
|
||||||
|
|
||||||
@ -15,18 +14,7 @@ from bigchaindb import db
|
|||||||
from bigchaindb.version import __version__
|
from bigchaindb.version import __version__
|
||||||
|
|
||||||
|
|
||||||
def start_temp_rethinkdb(port=0, directory=None):
|
def start_rethinkdb():
|
||||||
directory = directory or tempfile.mkdtemp()
|
|
||||||
|
|
||||||
extra_opts = ['--cluster-port', '0',
|
|
||||||
'--driver-port', str(port),
|
|
||||||
'--no-http-admin',
|
|
||||||
'--directory', directory]
|
|
||||||
|
|
||||||
return start_rethinkdb(wait_for_db=False, extra_opts=extra_opts)
|
|
||||||
|
|
||||||
|
|
||||||
def start_rethinkdb(wait_for_db=True, extra_opts=None):
|
|
||||||
"""Start RethinkDB as a child process and wait for it to be
|
"""Start RethinkDB as a child process and wait for it to be
|
||||||
available.
|
available.
|
||||||
|
|
||||||
@ -40,28 +28,21 @@ def start_rethinkdb(wait_for_db=True, extra_opts=None):
|
|||||||
be started.
|
be started.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not extra_opts:
|
proc = subprocess.Popen(['rethinkdb', '--bind', 'all'],
|
||||||
extra_opts = []
|
|
||||||
|
|
||||||
proc = subprocess.Popen(['rethinkdb', '--bind', 'all'] + extra_opts,
|
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
|
|
||||||
dbname = bigchaindb.config['database']['name']
|
dbname = bigchaindb.config['database']['name']
|
||||||
line = ''
|
line = ''
|
||||||
port = None
|
|
||||||
|
|
||||||
for line in proc.stdout:
|
for line in proc.stdout:
|
||||||
if line.startswith('Listening for client driver'):
|
|
||||||
port = int(line.split()[-1])
|
|
||||||
if line.startswith('Server ready'):
|
if line.startswith('Server ready'):
|
||||||
|
|
||||||
# FIXME: seems like tables are not ready when the server is ready,
|
# FIXME: seems like tables are not ready when the server is ready,
|
||||||
# that's why we need to query RethinkDB to know the state
|
# that's why we need to query RethinkDB to know the state
|
||||||
# of the database. This code assumes the tables are ready
|
# of the database. This code assumes the tables are ready
|
||||||
# when the database is ready. This seems a valid assumption.
|
# when the database is ready. This seems a valid assumption.
|
||||||
|
|
||||||
if wait_for_db:
|
|
||||||
try:
|
try:
|
||||||
conn = db.get_conn()
|
conn = db.get_conn()
|
||||||
# Before checking if the db is ready, we need to query
|
# Before checking if the db is ready, we need to query
|
||||||
@ -71,7 +52,7 @@ def start_rethinkdb(wait_for_db=True, extra_opts=None):
|
|||||||
except (r.ReqlOpFailedError, r.ReqlDriverError) as exc:
|
except (r.ReqlOpFailedError, r.ReqlDriverError) as exc:
|
||||||
raise StartupError('Error waiting for the database `{}` '
|
raise StartupError('Error waiting for the database `{}` '
|
||||||
'to be ready'.format(dbname)) from exc
|
'to be ready'.format(dbname)) from exc
|
||||||
return proc, port
|
return proc
|
||||||
|
|
||||||
# We are here when we exhaust the stdout of the process.
|
# We are here when we exhaust the stdout of the process.
|
||||||
# The last `line` contains info about the error.
|
# The last `line` contains info about the error.
|
||||||
|
@ -228,7 +228,7 @@ class Bigchain(object):
|
|||||||
# First, get information on all blocks which contain this transaction
|
# First, get information on all blocks which contain this transaction
|
||||||
response = self.connection.run(
|
response = self.connection.run(
|
||||||
r.table('bigchain', read_mode=self.read_mode)
|
r.table('bigchain', read_mode=self.read_mode)
|
||||||
.get_all(value, index=index)\
|
.get_all(value, index=index)
|
||||||
.pluck('votes', 'id', {'block': ['voters']}))
|
.pluck('votes', 'id', {'block': ['voters']}))
|
||||||
|
|
||||||
return list(response)
|
return list(response)
|
||||||
|
@ -67,7 +67,7 @@ def test_bigchain_run_start(mock_run_configure, mock_processes_start, mock_db_in
|
|||||||
run_start(args)
|
run_start(args)
|
||||||
|
|
||||||
|
|
||||||
@patch('bigchaindb.commands.utils.start_rethinkdb', return_value=(Mock(), 2))
|
@patch('bigchaindb.commands.utils.start_rethinkdb', return_value=Mock())
|
||||||
def test_bigchain_run_start_with_rethinkdb(mock_start_rethinkdb,
|
def test_bigchain_run_start_with_rethinkdb(mock_start_rethinkdb,
|
||||||
mock_run_configure,
|
mock_run_configure,
|
||||||
mock_processes_start,
|
mock_processes_start,
|
||||||
@ -216,7 +216,7 @@ def test_start_rethinkdb_returns_a_process_when_successful(mock_popen):
|
|||||||
mock_popen.return_value = Mock(stdout=[
|
mock_popen.return_value = Mock(stdout=[
|
||||||
'Listening for client driver 1234',
|
'Listening for client driver 1234',
|
||||||
'Server ready'])
|
'Server ready'])
|
||||||
assert utils.start_rethinkdb() == (mock_popen.return_value, 1234)
|
assert utils.start_rethinkdb() is mock_popen.return_value
|
||||||
|
|
||||||
|
|
||||||
@patch('subprocess.Popen')
|
@patch('subprocess.Popen')
|
||||||
@ -228,15 +228,6 @@ def test_start_rethinkdb_exits_when_cannot_start(mock_popen):
|
|||||||
utils.start_rethinkdb()
|
utils.start_rethinkdb()
|
||||||
|
|
||||||
|
|
||||||
@patch('subprocess.Popen')
|
|
||||||
def test_start_temp_rethinkdb_returns_a_process_when_successful(mock_popen):
|
|
||||||
from bigchaindb.commands import utils
|
|
||||||
mock_popen.return_value = Mock(stdout=[
|
|
||||||
'Listening for client driver 1234',
|
|
||||||
'Server ready'])
|
|
||||||
assert utils.start_temp_rethinkdb() == (mock_popen.return_value, 1234)
|
|
||||||
|
|
||||||
|
|
||||||
@patch('rethinkdb.ast.Table.reconfigure')
|
@patch('rethinkdb.ast.Table.reconfigure')
|
||||||
def test_set_shards(mock_reconfigure, monkeypatch, b):
|
def test_set_shards(mock_reconfigure, monkeypatch, b):
|
||||||
from bigchaindb.commands.bigchain import run_set_shards
|
from bigchaindb.commands.bigchain import run_set_shards
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
from unittest.mock import patch
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import rethinkdb as r
|
import rethinkdb as r
|
||||||
|
|
||||||
from bigchaindb.commands.utils import start_temp_rethinkdb
|
|
||||||
from bigchaindb.db.utils import Connection
|
from bigchaindb.db.utils import Connection
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user