From b2670fceb70a9d8f9d00c74eeba5404ea2defb85 Mon Sep 17 00:00:00 2001 From: Matt Kwong Date: Mon, 9 Jul 2018 14:22:04 -0700 Subject: [PATCH] Add error handling for when a test result cannot be parsed --- .../python_utils/upload_rbe_results.py | 65 +++++++++++++------ 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/tools/run_tests/python_utils/upload_rbe_results.py b/tools/run_tests/python_utils/upload_rbe_results.py index f35869cd4b7..d29ebc6219a 100644 --- a/tools/run_tests/python_utils/upload_rbe_results.py +++ b/tools/run_tests/python_utils/upload_rbe_results.py @@ -186,26 +186,51 @@ if __name__ == "__main__": result = 'UNKNOWN' else: result = 'PASSED' - bq_rows.append({ - 'insertId': str(uuid.uuid4()), - 'json': { - 'job_name': - os.getenv('KOKORO_JOB_NAME'), - 'build_id': - os.getenv('KOKORO_BUILD_NUMBER'), - 'build_url': - 'https://source.cloud.google.com/results/invocations/%s' % - invocation_id, - 'test_target': - action['id']['targetId'], - 'test_case': - test_case['testCase']['caseName'], - 'result': - result, - 'timestamp': - action['timing']['startTime'], - } - }) + try: + bq_rows.append({ + 'insertId': str(uuid.uuid4()), + 'json': { + 'job_name': + os.getenv('KOKORO_JOB_NAME'), + 'build_id': + os.getenv('KOKORO_BUILD_NUMBER'), + 'build_url': + 'https://source.cloud.google.com/results/invocations/%s' + % invocation_id, + 'test_target': + action['id']['targetId'], + 'test_case': + test_case['testCase']['caseName'], + 'result': + result, + 'timestamp': + action['timing']['startTime'], + } + }) + except Exception as e: + print('Failed to parse test result. Error: %s' % str(e)) + print(json.dumps(test_case, indent=4)) + bq_rows.append({ + 'insertId': str(uuid.uuid4()), + 'json': { + 'job_name': + os.getenv('KOKORO_JOB_NAME'), + 'build_id': + os.getenv('KOKORO_BUILD_NUMBER'), + 'build_url': + 'https://source.cloud.google.com/results/invocations/%s' + % invocation_id, + 'test_target': + action['id']['targetId'], + 'test_case': + 'N/A', + 'result': + 'UNPARSEABLE', + 'timestamp': + 'N/A', + } + }) + # BigQuery sometimes fails with large uploads, so batch 1,000 rows at a time. for i in range((len(bq_rows) / 1000) + 1): _upload_results_to_bq(bq_rows[i * 1000:(i + 1) * 1000])