Remove unused code

This commit is contained in:
vrde 2016-09-07 17:32:34 +02:00
parent b8e6b0b830
commit b9fba73c14
No known key found for this signature in database
GPG Key ID: 6581C7C39B3D397D
5 changed files with 17 additions and 47 deletions

View File

@ -156,7 +156,7 @@ def run_start(args):
if args.start_rethinkdb:
try:
proc, port = utils.start_rethinkdb()
proc = utils.start_rethinkdb()
except StartupError as e:
sys.exit('Error starting RethinkDB, reason is: {}'.format(e))
logger.info('RethinkDB started with PID %s' % proc.pid)

View File

@ -5,7 +5,6 @@ for ``argparse.ArgumentParser``.
import argparse
import multiprocessing as mp
import subprocess
import tempfile
import rethinkdb as r
@ -15,18 +14,7 @@ from bigchaindb import db
from bigchaindb.version import __version__
def start_temp_rethinkdb(port=0, directory=None):
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):
def start_rethinkdb():
"""Start RethinkDB as a child process and wait for it to be
available.
@ -40,38 +28,31 @@ def start_rethinkdb(wait_for_db=True, extra_opts=None):
be started.
"""
if not extra_opts:
extra_opts = []
proc = subprocess.Popen(['rethinkdb', '--bind', 'all'] + extra_opts,
proc = subprocess.Popen(['rethinkdb', '--bind', 'all'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True)
dbname = bigchaindb.config['database']['name']
line = ''
port = None
for line in proc.stdout:
if line.startswith('Listening for client driver'):
port = int(line.split()[-1])
if line.startswith('Server 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
# of the database. This code assumes the tables are ready
# when the database is ready. This seems a valid assumption.
if wait_for_db:
try:
conn = db.get_conn()
# Before checking if the db is ready, we need to query
# the server to check if it contains that db
if r.db_list().contains(dbname).run(conn):
r.db(dbname).wait().run(conn)
except (r.ReqlOpFailedError, r.ReqlDriverError) as exc:
raise StartupError('Error waiting for the database `{}` '
'to be ready'.format(dbname)) from exc
return proc, port
try:
conn = db.get_conn()
# Before checking if the db is ready, we need to query
# the server to check if it contains that db
if r.db_list().contains(dbname).run(conn):
r.db(dbname).wait().run(conn)
except (r.ReqlOpFailedError, r.ReqlDriverError) as exc:
raise StartupError('Error waiting for the database `{}` '
'to be ready'.format(dbname)) from exc
return proc
# We are here when we exhaust the stdout of the process.
# The last `line` contains info about the error.

View File

@ -228,7 +228,7 @@ class Bigchain(object):
# First, get information on all blocks which contain this transaction
response = self.connection.run(
r.table('bigchain', read_mode=self.read_mode)
.get_all(value, index=index)\
.get_all(value, index=index)
.pluck('votes', 'id', {'block': ['voters']}))
return list(response)

View File

@ -67,7 +67,7 @@ def test_bigchain_run_start(mock_run_configure, mock_processes_start, mock_db_in
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,
mock_run_configure,
mock_processes_start,
@ -216,7 +216,7 @@ def test_start_rethinkdb_returns_a_process_when_successful(mock_popen):
mock_popen.return_value = Mock(stdout=[
'Listening for client driver 1234',
'Server ready'])
assert utils.start_rethinkdb() == (mock_popen.return_value, 1234)
assert utils.start_rethinkdb() is mock_popen.return_value
@patch('subprocess.Popen')
@ -228,15 +228,6 @@ def test_start_rethinkdb_exits_when_cannot_start(mock_popen):
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')
def test_set_shards(mock_reconfigure, monkeypatch, b):
from bigchaindb.commands.bigchain import run_set_shards

View File

@ -1,10 +1,8 @@
from unittest.mock import patch
from threading import Thread
import pytest
import rethinkdb as r
from bigchaindb.commands.utils import start_temp_rethinkdb
from bigchaindb.db.utils import Connection