mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Better unittests
Simplify code
This commit is contained in:
parent
5fedabe586
commit
9c0d696b7e
@ -104,11 +104,10 @@ def initialize_replica_set(conn):
|
|||||||
if exc_info.details['codeName'] == 'AlreadyInitialized':
|
if exc_info.details['codeName'] == 'AlreadyInitialized':
|
||||||
logger.info('Replica set already initialized')
|
logger.info('Replica set already initialized')
|
||||||
return
|
return
|
||||||
else:
|
raise
|
||||||
raise
|
else:
|
||||||
|
_wait_for_replica_set_initialization(conn)
|
||||||
_wait_for_replica_set_initialization(conn)
|
logger.info('Initialized replica set')
|
||||||
logger.info('Initialized replica set')
|
|
||||||
|
|
||||||
|
|
||||||
def _get_replica_set_name(conn):
|
def _get_replica_set_name(conn):
|
||||||
@ -151,7 +150,6 @@ def _wait_for_replica_set_initialization(conn):
|
|||||||
logger.info('Waiting for mongodb replica set initialization')
|
logger.info('Waiting for mongodb replica set initialization')
|
||||||
while True:
|
while True:
|
||||||
logs = conn.conn.admin.command('getLog', 'rs')['log']
|
logs = conn.conn.admin.command('getLog', 'rs')['log']
|
||||||
for line in logs:
|
if any('database writes are now permitted' in line for line in logs):
|
||||||
if 'database writes are now permitted' in line:
|
|
||||||
return
|
return
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
@ -107,7 +107,7 @@ def test_drop():
|
|||||||
assert dbname not in conn.conn.database_names()
|
assert dbname not in conn.conn.database_names()
|
||||||
|
|
||||||
|
|
||||||
def test_get_replica_set_name():
|
def test_get_replica_set_name_not_enabled():
|
||||||
from pymongo.database import Database
|
from pymongo.database import Database
|
||||||
from bigchaindb import backend
|
from bigchaindb import backend
|
||||||
from bigchaindb.backend.mongodb.schema import _get_replica_set_name
|
from bigchaindb.backend.mongodb.schema import _get_replica_set_name
|
||||||
@ -123,6 +123,14 @@ def test_get_replica_set_name():
|
|||||||
with pytest.raises(ConfigurationError):
|
with pytest.raises(ConfigurationError):
|
||||||
_get_replica_set_name(conn)
|
_get_replica_set_name(conn)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_replica_set_name_command_line():
|
||||||
|
from pymongo.database import Database
|
||||||
|
from bigchaindb import backend
|
||||||
|
from bigchaindb.backend.mongodb.schema import _get_replica_set_name
|
||||||
|
|
||||||
|
conn = backend.connect()
|
||||||
|
|
||||||
# replSet option set through the command line
|
# replSet option set through the command line
|
||||||
cmd_line_opts = {'argv': ['mongod', '--dbpath=/data', '--replSet=rs0'],
|
cmd_line_opts = {'argv': ['mongod', '--dbpath=/data', '--replSet=rs0'],
|
||||||
'ok': 1.0,
|
'ok': 1.0,
|
||||||
@ -131,6 +139,14 @@ def test_get_replica_set_name():
|
|||||||
with patch.object(Database, 'command', return_value=cmd_line_opts):
|
with patch.object(Database, 'command', return_value=cmd_line_opts):
|
||||||
assert _get_replica_set_name(conn) == 'rs0'
|
assert _get_replica_set_name(conn) == 'rs0'
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_replica_set_name_config_file():
|
||||||
|
from pymongo.database import Database
|
||||||
|
from bigchaindb import backend
|
||||||
|
from bigchaindb.backend.mongodb.schema import _get_replica_set_name
|
||||||
|
|
||||||
|
conn = backend.connect()
|
||||||
|
|
||||||
# replSet option set through the config file
|
# replSet option set through the config file
|
||||||
cmd_line_opts = {'argv': ['mongod', '--dbpath=/data', '--replSet=rs0'],
|
cmd_line_opts = {'argv': ['mongod', '--dbpath=/data', '--replSet=rs0'],
|
||||||
'ok': 1.0,
|
'ok': 1.0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user