diff --git a/hived/jsonsocket.py b/hived/jsonsocket.py index 0ce98f58954b5f8e01ce566b192c48a08f2106f9..65a77eda641b96e8177e6e805dd80a99d48ba403 100644 --- a/hived/jsonsocket.py +++ b/hived/jsonsocket.py @@ -41,7 +41,7 @@ class JSONSocket(object): """ data - complete binary form of json request (ends with '\r\n' json - json request as python dict - + return value in form of json response as python dict """ if data == None: @@ -57,7 +57,7 @@ class JSONSocket(object): #if response == {}: # print("response is empty for request:", request.decode("utf-8")) return status, response - + def __call__(self, data=None, json=None): return self.request(data, json) @@ -79,14 +79,14 @@ class JSONSocket(object): return True, r else: return False, r - + return False, {} - + def __del__(self): if self.__sock: self.__sock.close() - + def hived_call(host, data=None, json=None, max_tries=10, timeout=0.1): """ host - [http[s]://<ip_address>:<port> @@ -97,7 +97,7 @@ def hived_call(host, data=None, json=None, max_tries=10, timeout=0.1): # except: # print("Cannot open socket for:", host) # return False, {} - + for i in range(max_tries): try: jsocket = JSONSocket(host, None, "/rpc", timeout) @@ -121,4 +121,4 @@ def hived_call(host, data=None, json=None, max_tries=10, timeout=0.1): def universal_call(url, data, *args, **kwargs): from requests import post result = post(url, json=data) - return [result.status_code, result.text] + return [result.status_code, result.content.decode('utf-8')] diff --git a/hived/test_ah_enum_virtual_ops.py b/hived/test_ah_enum_virtual_ops.py index 939518eb4b8c59b777a971e9dd133f51eca09ec2..ef220c292b86cd384ead823c8d48cbeff7348743 100755 --- a/hived/test_ah_enum_virtual_ops.py +++ b/hived/test_ah_enum_virtual_ops.py @@ -9,9 +9,8 @@ import sys import json import os from argparse import ArgumentParser -from concurrent.futures import ThreadPoolExecutor +from concurrent.futures import Future, ThreadPoolExecutor from concurrent.futures import ProcessPoolExecutor -from concurrent.futures import wait from jsonsocket import universal_call as hived_call from pathlib import Path @@ -20,9 +19,10 @@ wdir = Path() errors = 0 -def future_end_cb(future): +def future_end_cb(future : Future): global errors - if future.result() == False: + exc = future.exception() + if exc is not None or future.result() == False: errors += 1 diff --git a/hived/test_ah_get_account_history.py b/hived/test_ah_get_account_history.py index f16e3314db33e6ca12561a6e4a0ab59449d5d68c..83c611240a09ca91a12fe6d6a5fc159428f13166 100755 --- a/hived/test_ah_get_account_history.py +++ b/hived/test_ah_get_account_history.py @@ -9,9 +9,8 @@ from argparse import ArgumentParser import sys import json import os -from concurrent.futures import ThreadPoolExecutor +from concurrent.futures import Future, ThreadPoolExecutor from concurrent.futures import ProcessPoolExecutor -from concurrent.futures import wait from jsonsocket import universal_call as hived_call from list_account import list_accounts from pathlib import Path @@ -21,9 +20,10 @@ wdir = Path() errors = 0 -def future_end_cb(future): +def future_end_cb(future : Future): global errors - if future.result() == False: + exc = future.exception() + if exc is not None or future.result() == False: errors += 1 diff --git a/hived/test_ah_get_ops_in_block.py b/hived/test_ah_get_ops_in_block.py index 17a244600d2c7ba5cf36e03b4d5f8e1a92b8d99d..046fb7f7716713777d288bd2c5cdd9486ccb802a 100755 --- a/hived/test_ah_get_ops_in_block.py +++ b/hived/test_ah_get_ops_in_block.py @@ -8,15 +8,11 @@ from argparse import ArgumentParser import sys -import json +import simplejson as json import os -import shutil -from jsonsocket import JSONSocket from jsonsocket import universal_call as hived_call -from concurrent.futures import ThreadPoolExecutor +from concurrent.futures import Future, ThreadPoolExecutor from concurrent.futures import ProcessPoolExecutor -from concurrent.futures import Future -from concurrent.futures import wait from pathlib import Path @@ -24,9 +20,10 @@ wdir = Path() errors = 0 -def future_end_cb(future): +def future_end_cb(future : Future): global errors - if future.result() == False: + exc = future.exception() + if exc is not None or future.result() == False: errors += 1 @@ -139,9 +136,6 @@ def compare_results(f_block, l_block, url1, url2, max_tries=10, timeout=0.1): json1 = json.loads(json1) json2 = json.loads(json2) - #status1, json1 = hived_call(url1, data=request, max_tries=max_tries, timeout=timeout) - #status2, json2 = hived_call(url2, data=request, max_tries=max_tries, timeout=timeout) - if status1 == False or status2 == False or json1 != json2: print("Difference @block: {}\n".format(i)) diff --git a/hived/test_ah_get_transaction.py b/hived/test_ah_get_transaction.py index 8eb3638a8d4cbbbad237f4d735b3b15a86b19c78..2f107c8d13ca1c76f1ba886be1e1e56bbe42c1ee 100755 --- a/hived/test_ah_get_transaction.py +++ b/hived/test_ah_get_transaction.py @@ -9,9 +9,8 @@ import sys import json import os from argparse import ArgumentParser -from concurrent.futures import ThreadPoolExecutor +from concurrent.futures import Future, ThreadPoolExecutor from concurrent.futures import ProcessPoolExecutor -from concurrent.futures import wait from jsonsocket import universal_call as hived_call from pathlib import Path @@ -20,9 +19,10 @@ wdir = Path() errors = 0 -def future_end_cb(future): +def future_end_cb(future : Future): global errors - if future.result() == False: + exc = future.exception() + if exc is not None or future.result() == False: errors += 1