pytest: wait until mock is called for set_feerates.

Got a spurious failure in test_no_fee_estimate; we fired too soon from the logs (presumably
we raced in on the first response, but estimatesmartfee gets called 3 times).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-09-20 13:52:15 +09:30 committed by Christian Decker
parent d5c3626fa7
commit e41e1a177e
2 changed files with 7 additions and 1 deletions

View File

@ -29,6 +29,7 @@ class BitcoinRpcProxy(object):
self.app.add_url_rule("/", "API entrypoint", self.proxy, methods=['POST'])
self.rpcport = rpcport
self.mocks = {}
self.mock_counts = {}
self.bitcoind = bitcoind
self.request_count = 0
@ -40,8 +41,10 @@ class BitcoinRpcProxy(object):
# If we have set a mock for this method reply with that instead of
# forwarding the request.
if method in self.mocks and type(method) == dict:
self.mock_counts[method] += 1
return self.mocks[method]
elif method in self.mocks and callable(self.mocks[method]):
self.mock_counts[method] += 1
return self.mocks[method](r)
try:
@ -100,5 +103,6 @@ class BitcoinRpcProxy(object):
"""
if response is not None:
self.mocks[method] = response
self.mock_counts[method] = 0
elif method in self.mocks:
del self.mocks[method]

View File

@ -627,8 +627,10 @@ class LightningNode(object):
}
self.daemon.rpcproxy.mock_rpc('estimatesmartfee', mock_estimatesmartfee)
# Technically, this waits until it's called, not until it's processed.
# We wait until all three levels have been called.
if wait_for_effect:
self.daemon.wait_for_log('Feerate estimate for .* set to')
wait_for(lambda: self.daemon.rpcproxy.mock_counts['estimatesmartfee'] >= 3)
class NodeFactory(object):