Skip to content

Commit

Permalink
qa: Allow for partial_match when checking init error
Browse files Browse the repository at this point in the history
This allows the tests to pass on different platforms
  • Loading branch information
MarcoFalke committed Mar 19, 2018
1 parent 5812273 commit fae1374
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
12 changes: 8 additions & 4 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def is_node_stopped(self):
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):
wait_until(self.is_node_stopped, timeout=timeout)

def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, *args, **kwargs):
def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, partial_match=False, *args, **kwargs):
"""Attempt to start the node and expect it to raise an error.
extra_args: extra arguments to pass through to bitcoind
Expand All @@ -187,9 +187,13 @@ def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, *ar
# Check stderr for expected message
if expected_msg is not None:
log_stderr.seek(0)
stderr = log_stderr.read().decode('utf-8')
if re.fullmatch(expected_msg + '\n', stderr) is None:
raise AssertionError('Expected message "{}" does not match stderr:\n"{}"'.format(expected_msg, stderr))
stderr = log_stderr.read().decode('utf-8').strip()
if partial_match:
if re.search(expected_msg, stderr, flags=re.MULTILINE) is None:
raise AssertionError('Expected message "{}" does not partially match stderr:\n"{}"'.format(expected_msg, stderr))
else:
if re.fullmatch(expected_msg, stderr) is None:
raise AssertionError('Expected message "{}" does not fully match stderr:\n"{}"'.format(expected_msg, stderr))
else:
if expected_msg is None:
assert_msg = "bitcoind should have exited with an error"
Expand Down
19 changes: 7 additions & 12 deletions test/functional/wallet_multiwallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Verify that a bitcoind node can load multiple wallet files
"""
import os
import re
import shutil

from test_framework.test_framework import BitcoinTestFramework
Expand Down Expand Up @@ -60,11 +61,8 @@ def run_test(self):
assert_equal(os.path.isfile(wallet_dir(wallet_name)), True)

# should not initialize if wallet path can't be created
exp_stderr = "\n\n\*+\n" + \
"EXCEPTION: .*\n" + \
"boost::filesystem::create_directory: Not a directory:.*\n" + \
"bitcoin in .*\n"
self.nodes[0].assert_start_raises_init_error(['-wallet=wallet.dat/bad'], exp_stderr)
exp_stderr = "boost::filesystem::create_directory: (The system cannot find the path specified|Not a directory):"
self.nodes[0].assert_start_raises_init_error(['-wallet=wallet.dat/bad'], exp_stderr, partial_match=True)

self.nodes[0].assert_start_raises_init_error(['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" does not exist')
self.nodes[0].assert_start_raises_init_error(['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" is a relative path', cwd=data_dir())
Expand All @@ -75,11 +73,8 @@ def run_test(self):

# should not initialize if one wallet is a copy of another
shutil.copyfile(wallet_dir('w8'), wallet_dir('w8_copy'))
exp_stderr = "\n\n\*+\n" + \
"EXCEPTION: .*\n" + \
"CDB: Can't open database w8_copy \(duplicates fileid \w+ from w8\)\s*\n" + \
"bitcoin in .*\n"
self.nodes[0].assert_start_raises_init_error(['-wallet=w8', '-wallet=w8_copy'], exp_stderr)
exp_stderr = "CDB: Can't open database w8_copy \(duplicates fileid \w+ from w8\)"
self.nodes[0].assert_start_raises_init_error(['-wallet=w8', '-wallet=w8_copy'], exp_stderr, partial_match=True)

# should not initialize if wallet file is a symlink
os.symlink('w8', wallet_dir('w8_symlink'))
Expand All @@ -90,7 +85,7 @@ def run_test(self):
# should not initialize if the specified walletdir is not a directory
not_a_dir = wallet_dir('notadir')
open(not_a_dir, 'a').close()
self.nodes[0].assert_start_raises_init_error(['-walletdir=' + not_a_dir], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory')
self.nodes[0].assert_start_raises_init_error(['-walletdir=' + not_a_dir], 'Error: Specified -walletdir "' + re.escape(not_a_dir) + '" is not a directory')

# if wallets/ doesn't exist, datadir should be the default wallet dir
wallet_dir2 = data_dir('walletdir')
Expand All @@ -112,7 +107,7 @@ def run_test(self):
os.mkdir(competing_wallet_dir)
self.restart_node(0, ['-walletdir=' + competing_wallet_dir])
exp_stderr = "Error: Error initializing wallet database environment \"\S+competing_walletdir\"!"
self.nodes[1].assert_start_raises_init_error(['-walletdir=' + competing_wallet_dir], exp_stderr)
self.nodes[1].assert_start_raises_init_error(['-walletdir=' + competing_wallet_dir], exp_stderr, partial_match=True)

self.restart_node(0, extra_args)

Expand Down

0 comments on commit fae1374

Please sign in to comment.