Allow more information to be returned when an async rpc fails
This commit is contained in:
@@ -385,29 +385,34 @@ def assert_raises(exc, fun, *args, **kwds):
|
|||||||
# Returns txid if operation was a success or None
|
# Returns txid if operation was a success or None
|
||||||
def wait_and_assert_operationid_status(node, myopid, in_status='success', in_errormsg=None):
|
def wait_and_assert_operationid_status(node, myopid, in_status='success', in_errormsg=None):
|
||||||
print('waiting for async operation {}'.format(myopid))
|
print('waiting for async operation {}'.format(myopid))
|
||||||
opids = []
|
result = None
|
||||||
opids.append(myopid)
|
for x in xrange(1, 300): # 300 is the timeout
|
||||||
timeout = 300
|
results = node.z_getoperationresult([myopid])
|
||||||
status = None
|
if len(results) > 0:
|
||||||
errormsg = None
|
result = results[0]
|
||||||
txid = None
|
|
||||||
for x in xrange(1, timeout):
|
|
||||||
results = node.z_getoperationresult(opids)
|
|
||||||
if len(results)==0:
|
|
||||||
time.sleep(1)
|
|
||||||
else:
|
|
||||||
status = results[0]["status"]
|
|
||||||
if status == "failed":
|
|
||||||
errormsg = results[0]['error']['message']
|
|
||||||
elif status == "success":
|
|
||||||
txid = results[0]['result']['txid']
|
|
||||||
break
|
break
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
assert_true(result is not None, "timeout occured")
|
||||||
|
status = result['status']
|
||||||
|
|
||||||
|
txid = None
|
||||||
|
errormsg = None
|
||||||
|
if status == "failed":
|
||||||
|
errormsg = result['error']['message']
|
||||||
|
elif status == "success":
|
||||||
|
txid = result['result']['txid']
|
||||||
|
|
||||||
if os.getenv("PYTHON_DEBUG", ""):
|
if os.getenv("PYTHON_DEBUG", ""):
|
||||||
print('...returned status: {}'.format(status))
|
print('...returned status: {}'.format(status))
|
||||||
if errormsg is not None:
|
if errormsg is not None:
|
||||||
print('...returned error: {}'.format(errormsg))
|
print('...returned error: {}'.format(errormsg))
|
||||||
assert_equal(in_status, status)
|
|
||||||
|
assert_equal(in_status, status, "Operation returned mismatched status. Error Message: {}".format(errormsg))
|
||||||
|
|
||||||
if errormsg is not None:
|
if errormsg is not None:
|
||||||
assert(in_errormsg is not None)
|
assert_true(in_errormsg is not None, "No error retured. Expected: {}".format(errormsg))
|
||||||
assert_equal(in_errormsg in errormsg, True)
|
assert_true(in_errormsg in errormsg, "Error returned: {}. Error expected: {}".format(errormsg, in_errormsg))
|
||||||
return txid
|
return result # if there was an error return the result
|
||||||
|
else:
|
||||||
|
return txid # otherwise return the txid
|
||||||
|
|||||||
Reference in New Issue
Block a user