aboutsummaryrefslogtreecommitdiff
path: root/test/functional/feature_filelock.py
diff options
context:
space:
mode:
authorChun Kuan Lee <ken2812221@gmail.com>2018-10-08 00:24:20 +0800
committerChun Kuan Lee <ken2812221@gmail.com>2018-10-19 02:29:25 +0800
commit369244f654c9e36b803e841eb30fd0aa2960087a (patch)
treecc74ae7e3a5c7ae7f463bd409f0492491e25e33b /test/functional/feature_filelock.py
parentfe23553edd84b0247e05ec3de023944c558afd54 (diff)
downloadbitcoin-369244f654c9e36b803e841eb30fd0aa2960087a.tar.xz
utils: Fix broken Windows filelock
Diffstat (limited to 'test/functional/feature_filelock.py')
-rwxr-xr-xtest/functional/feature_filelock.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/functional/feature_filelock.py b/test/functional/feature_filelock.py
new file mode 100755
index 0000000000..9fb0d35a68
--- /dev/null
+++ b/test/functional/feature_filelock.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+"""Check that it's not possible to start a second bitcoind instance using the same datadir or wallet."""
+import os
+
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.test_node import ErrorMatch
+
+class FilelockTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.setup_clean_chain = True
+ self.num_nodes = 2
+
+ def setup_network(self):
+ self.add_nodes(self.num_nodes, extra_args=None)
+ self.nodes[0].start([])
+ self.nodes[0].wait_for_rpc_connection()
+
+ def run_test(self):
+ datadir = os.path.join(self.nodes[0].datadir, 'regtest')
+ self.log.info("Using datadir {}".format(datadir))
+
+ self.log.info("Check that we can't start a second bitcoind instance using the same datadir")
+ expected_msg = "Error: Cannot obtain a lock on data directory {}. Bitcoin Core is probably already running.".format(datadir)
+ self.nodes[1].assert_start_raises_init_error(extra_args=['-datadir={}'.format(self.nodes[0].datadir), '-noserver'], expected_msg=expected_msg)
+
+ if self.is_wallet_compiled():
+ wallet_dir = os.path.join(datadir, 'wallets')
+ self.log.info("Check that we can't start a second bitcoind instance using the same wallet")
+ expected_msg = "Error: Error initializing wallet database environment"
+ self.nodes[1].assert_start_raises_init_error(extra_args=['-walletdir={}'.format(wallet_dir), '-noserver'], expected_msg=expected_msg, match=ErrorMatch.PARTIAL_REGEX)
+
+if __name__ == '__main__':
+ FilelockTest().main()