diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 79130c9bd..10391864a 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -385,29 +385,34 @@ def assert_raises(exc, fun, *args, **kwds): # Returns txid if operation was a success or None def wait_and_assert_operationid_status(node, myopid, in_status='success', in_errormsg=None): print('waiting for async operation {}'.format(myopid)) - opids = [] - opids.append(myopid) - timeout = 300 - status = None - errormsg = None - 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'] + result = None + for x in xrange(1, 300): # 300 is the timeout + results = node.z_getoperationresult([myopid]) + if len(results) > 0: + result = results[0] 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", ""): print('...returned status: {}'.format(status)) if errormsg is not None: 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: - assert(in_errormsg is not None) - assert_equal(in_errormsg in errormsg, True) - return txid + assert_true(in_errormsg is not None, "No error retured. Expected: {}".format(errormsg)) + assert_true(in_errormsg in errormsg, "Error returned: {}. Error expected: {}".format(errormsg, in_errormsg)) + return result # if there was an error return the result + else: + return txid # otherwise return the txid