Consider this:
--- i/test/functional/wallet_keypool.py
+++ w/test/functional/wallet_keypool.py
@@ -124,16 +124,13 @@ class KeyPoolTest(BitcoinTestFramework):
# refill keypool with three new addresses
nodes[0].walletpassphrase('test', 1)
nodes[0].keypoolrefill(3)
# test walletpassphrase timeout
- # CScheduler relies on condition_variable::wait_until() which is slightly
- # less accurate than libevent's event trigger. We'll give it 2
- # seconds to execute a 1 second scheduled event.
- time.sleep(2)
+ nodes[0].wait_until(lambda: nodes[0].getwalletinfo()["unlocked_until"] == 0)
assert_equal(nodes[0].getwalletinfo()["unlocked_until"], 0)
# drain the keypool
for _ in range(3):
nodes[0].getnewaddress()
assert_raises_rpc_error(-12, "Keypool ran out", nodes[0].getnewaddress)
It makes the test ~1 second faster - does not wait needlessly when the passphrase has already been cleared after about 1 second in normal environments. Also is more reliable because it would adapt to slow environments.