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':
|
||||
logger.info('Replica set already initialized')
|
||||
return
|
||||
else:
|
||||
raise
|
||||
|
||||
_wait_for_replica_set_initialization(conn)
|
||||
logger.info('Initialized replica set')
|
||||
raise
|
||||
else:
|
||||
_wait_for_replica_set_initialization(conn)
|
||||
logger.info('Initialized replica set')
|
||||
|
||||
|
||||
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')
|
||||
while True:
|
||||
logs = conn.conn.admin.command('getLog', 'rs')['log']
|
||||
for line in logs:
|
||||
if 'database writes are now permitted' in line:
|
||||
if any('database writes are now permitted' in line for line in logs):
|
||||
return
|
||||
time.sleep(0.1)
|
||||
|
@ -107,7 +107,7 @@ def test_drop():
|
||||
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 bigchaindb import backend
|
||||
from bigchaindb.backend.mongodb.schema import _get_replica_set_name
|
||||
@ -123,6 +123,14 @@ def test_get_replica_set_name():
|
||||
with pytest.raises(ConfigurationError):
|
||||
_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
|
||||
cmd_line_opts = {'argv': ['mongod', '--dbpath=/data', '--replSet=rs0'],
|
||||
'ok': 1.0,
|
||||
@ -131,6 +139,14 @@ def test_get_replica_set_name():
|
||||
with patch.object(Database, 'command', return_value=cmd_line_opts):
|
||||
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
|
||||
cmd_line_opts = {'argv': ['mongod', '--dbpath=/data', '--replSet=rs0'],
|
||||
'ok': 1.0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user