diff --git a/serializer/serializer.c b/serializer/serializer.c index 562a1935..338d5b9c 100644 --- a/serializer/serializer.c +++ b/serializer/serializer.c @@ -260,7 +260,7 @@ status_t ta_send_transfer_req_deserialize(const char* const obj, } json_result = cJSON_GetObjectItemCaseSensitive(json_obj, "tag"); - if (json_result != NULL) { + if (json_result != NULL && json_result->valuestring != NULL) { tag_len = strnlen(json_result->valuestring, NUM_TRYTES_TAG); // If 'tag' is less than 27 trytes (NUM_TRYTES_TAG), expands it @@ -297,7 +297,7 @@ status_t ta_send_transfer_req_deserialize(const char* const obj, } json_result = cJSON_GetObjectItemCaseSensitive(json_obj, "message"); - if (json_result != NULL) { + if (json_result != NULL && json_result->valuestring != NULL) { if (raw_message) { msg_len = strlen(json_result->valuestring) * 2; req->msg_len = msg_len * 3; @@ -322,7 +322,8 @@ status_t ta_send_transfer_req_deserialize(const char* const obj, } json_result = cJSON_GetObjectItemCaseSensitive(json_obj, "address"); - if (json_result != NULL && (strnlen(json_result->valuestring, 81) == 81)) { + if (json_result != NULL && json_result->valuestring != NULL && + (strnlen(json_result->valuestring, 81) == 81)) { flex_trits_from_trytes(address_trits, NUM_TRITS_HASH, (const tryte_t*)json_result->valuestring, NUM_TRYTES_HASH, NUM_TRYTES_HASH); diff --git a/tests/regression/1_close_TA.sh b/tests/regression/1_close_TA.sh index 230128f4..84ba585c 100644 --- a/tests/regression/1_close_TA.sh +++ b/tests/regression/1_close_TA.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash wait $(ps aux | grep '[r]unner.py' | awk '{print $2}') -kill $(ps aux | grep '[.]/accelerator' | awk '{print $2}') -wait $! +wait $(kill $(ps aux | grep '[r]edis' | awk '{print $2}')) +wait $(kill $(ps aux | grep '[.]/accelerator' | awk '{print $2}')) trap 'exit 0' SIGTERM diff --git a/tests/regression/1_run_TA.sh b/tests/regression/1_run_TA.sh index fa2a63f9..18de721d 100644 --- a/tests/regression/1_run_TA.sh +++ b/tests/regression/1_run_TA.sh @@ -1,8 +1,10 @@ make +redis-server & + bazel run //accelerator & TA_pid=$! -sleep 20 +sleep 5 pip install --user -r tests/regression/requirements.txt diff --git a/tests/regression/runner.py b/tests/regression/runner.py index 372721ba..c2104be0 100644 --- a/tests/regression/runner.py +++ b/tests/regression/runner.py @@ -14,7 +14,7 @@ raw_url = sys.argv[1] elif len(sys.argv) == 3: raw_url = sys.argv[1] - # if DEBUG_FLAG field == `Y`, then starts debugging mode + # if DEBUG_FLAG field == `Y`, then starts debugging mode with less iteration in statistical tests if sys.argv[2] == 'y' or sys.argv[2] == 'Y': DEBUG_FLAG = True else: @@ -27,13 +27,14 @@ MSG_STATUS_CODE_405 = "[405] Method Not Allowed" MSG_STATUS_CODE_400 = "{\"message\":\"Invalid request header\"}" MSG_STATUS_CODE_404 = "404 Not Found" +MSG_STATUS_CODE_500 = "500" EMPTY_REPLY = "000" LEN_TAG = 27 LEN_ADDR = 81 LEN_MSG_SIGN = 2187 tryte_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ9" -if DEBUG_FLAG == True: +if sys.argv[2] == 'Y': TIMES_TOTAL = 2 else: TIMES_TOTAL = 100 @@ -97,7 +98,7 @@ def API(get_query, get_data=None, post_data=None, delay=True): return None if not response: response = "" - + if delay == True: time.sleep(2) return response @@ -122,7 +123,7 @@ def test_mam_send_msg(self): "JSON msg with wrong key" ] - pass_case = [0, 1] + pass_case = [0, 1, 4] for i in range(len(test_cases)): if i not in pass_case: test_cases[i].encode(encoding='utf-8') @@ -155,7 +156,8 @@ def test_mam_send_msg(self): LEN_ADDR)) else: self.assertTrue(EMPTY_REPLY in response[i] - or MSG_STATUS_CODE_404 in response[i]) + or MSG_STATUS_CODE_404 in response[i] + or MSG_STATUS_CODE_500 in response[i]) # Time Statistics payload = "Who are we? Just a speck of dust within the galaxy?" @@ -266,7 +268,7 @@ def test_send_transfer(self): logging.debug("send transfer i = " + str(i) + ", response = " + response[i]) - pass_case = [0, 1, 2] + pass_case = [0, 1, 2, 3] for i in range(len(response)): logging.debug("send transfer i = " + str(i) + ", response = " + response[i]) @@ -291,7 +293,8 @@ def test_send_transfer(self): LEN_MSG_SIGN)) else: self.assertTrue(EMPTY_REPLY in response[i] - or MSG_STATUS_CODE_404 in response[i]) + or MSG_STATUS_CODE_404 in response[i] + or MSG_STATUS_CODE_500 in response[i]) # Time Statistics time_cost = [] @@ -333,5 +336,5 @@ def test_send_transfer(self): logging.basicConfig(level=logging.INFO) unittest.main(argv=['first-arg-is-ignored'], exit=False) - if not unittest.TestResult().errors: + if len(unittest.TestResult().errors) != 0: exit(1)