Last active
March 3, 2020 17:52
-
-
Save jborean93/59005519e34d256cf35606564d2de5dc to your computer and use it in GitHub Desktop.
Simple script that turns the test.json output of https://github.com/ansible/ansible/blob/devel/hacking/shippable/download.py to a easy to view table of test target runtimes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import operator | |
import os | |
def get_raw_test_targets(test_path): | |
with open(test_path, mode='rb') as fd: | |
test_info = json.loads(fd.read().decode('utf-8')) | |
target_times = {} | |
for test in test_info: | |
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(): | |
target_times[target_name] = int(target_info.get('run_time_seconds', 0)) | |
return {k: v for k, v in sorted(target_times.items(), key=lambda i: i[1], reverse=True)} | |
def print_test_runtime(target_times): | |
target_name_max_len = 0 | |
for target_name in target_times.keys(): | |
target_name_max_len = max(target_name_max_len, len(target_name)) | |
print("%s | Seconds |" % ("Target Name".ljust(target_name_max_len),)) | |
print("%s | ------- |" % ("-" * target_name_max_len,)) | |
for target_name, target_time in target_times.items(): | |
print("%s | %s |" % (target_name.ljust(target_name_max_len), str(target_time).ljust(7))) | |
def main(): | |
test_path = os.path.join(os.path.dirname(__file__), 'shippable', 'test.json') | |
target_times = get_raw_test_targets(test_path) | |
# Split into x group(s) | |
group_count = 3 | |
group_info = {i: {'targets': [], 'total_time': 0} for i in range(1, group_count + 1)} | |
# Now add each test to the group with the lowest running time. | |
for target_name, target_time in target_times.items(): | |
index, total_time = min(enumerate([g['total_time'] for g in group_info.values()]), key=operator.itemgetter(1)) | |
group_info[index + 1]['targets'].append(target_name) | |
group_info[index + 1]['total_time'] = total_time + target_time | |
# Finally print a summary of the proposed test split. | |
for group_number, test_info in group_info.items(): | |
print("Group %d - Total Runtime (s): %d" % (group_number, test_info['total_time'])) | |
print_test_runtime({n: target_times[n] for n in test_info['targets']}) | |
print() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment