Get test data file directly in rebalance script (#70107)

Rather than looking through tests.json to find the data file, look for it explicitly
within a given target to avoid problems processing data in tests.json.
pull/70176/head
Sam Doran 5 years ago committed by GitHub
parent bc05415109
commit fd882e0e18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,10 +7,15 @@
""" """
CLI tool that analyses a Shippable run's test result and re-balances the test targets into new groups. CLI tool that analyses a Shippable run's test result and re-balances the test targets into new groups.
Before running this script you must run download.py like Before running this script you must run download.py like:
./download.py https://app.shippable.com/github/<team>/<repo>/runs/<run_num> --test-results --job-number x --job-number y ./download.py https://app.shippable.com/github/<team>/<repo>/runs/<run_num> --test-results --job-number x --job-number y
Or to get all job results from a run:
./download.py https://app.shippable.com/github/<team>/<repo>/runs/<run_num> --test-results --all
Set the dir <team>/<repo>/<run_num> as the value of '-p/--test-path' for this script. Set the dir <team>/<repo>/<run_num> as the value of '-p/--test-path' for this script.
""" """
@ -23,6 +28,8 @@ import operator
import os import os
import re import re
from glob import glob
try: try:
import argcomplete import argcomplete
except ImportError: except ImportError:
@ -72,22 +79,24 @@ def get_raw_test_targets(args, test_path):
target_times = {} target_times = {}
for job_id in os.listdir(test_path): for job_id in os.listdir(test_path):
json_path = os.path.join(test_path, job_id, 'test.json') json_path = os.path.join(test_path, job_id, 'test', 'testresults', 'data')
if not os.path.isfile(json_path):
# Some tests to do not have a data directory
if not os.path.exists(json_path):
continue
json_file = glob(os.path.join(json_path, '*integration-*.json'))[0]
if not os.path.isfile(json_file):
if args.verbose: if args.verbose:
print("The test json file '%s' does not exist or is not a file, skipping test job run" % json_path) print("The test json file '%s' does not exist or is not a file, skipping test job run" % json_file)
continue continue
with open(json_path, mode='rb') as fd: with open(json_file, mode='rb') as fd:
test_info = json.loads(fd.read().decode('utf-8')) test_info = json.loads(fd.read().decode('utf-8'))
for test in test_info: targets = test_info.get('targets', {})
if not test.get('path', '').endswith('.json') or 'contents' not in test.keys():
continue
info = json.loads(test['contents'])
for target_name, target_info in info.get('targets', {}).items(): for target_name, target_info in targets.items():
target_runtime = int(target_info.get('run_time_seconds', 0)) target_runtime = int(target_info.get('run_time_seconds', 0))
# If that target already is found and has a higher runtime than the current one, ignore this entry. # If that target already is found and has a higher runtime than the current one, ignore this entry.

Loading…
Cancel
Save