From 8fa294a33acf8a49f24d1a539b9c2d976fddbe5c Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Mon, 11 Mar 2019 15:14:09 -0700 Subject: [PATCH] Fix ansible-test coverage stub memory usage. (#53652) Split coverage stub files into multiple parts based on the number of lines in files included in each stub. This will keep memory usage down to avoid hanging on Shippable. --- test/runner/lib/cover.py | 23 ++++++++++++++++++++++- test/utils/shippable/shippable.sh | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/test/runner/lib/cover.py b/test/runner/lib/cover.py index 9e887dac54..3e61de6a95 100644 --- a/test/runner/lib/cover.py +++ b/test/runner/lib/cover.py @@ -55,7 +55,28 @@ def command_coverage_combine(args): sources = [] if args.stub: - groups['=stub'] = dict((source, set()) for source in sources) + stub_group = [] + stub_groups = [stub_group] + stub_line_limit = 500000 + stub_line_count = 0 + + for source in sources: + with open(source, 'r') as source_fd: + source_line_count = len(source_fd.read().splitlines()) + + stub_group.append(source) + stub_line_count += source_line_count + + if stub_line_count > stub_line_limit: + stub_line_count = 0 + stub_group = [] + stub_groups.append(stub_group) + + for stub_index, stub_group in enumerate(stub_groups): + if not stub_group: + continue + + groups['=stub-%02d' % (stub_index + 1)] = dict((source, set()) for source in stub_group) for coverage_file in coverage_files: counter += 1 diff --git a/test/utils/shippable/shippable.sh b/test/utils/shippable/shippable.sh index 8e90ab9095..90e0d5f908 100755 --- a/test/utils/shippable/shippable.sh +++ b/test/utils/shippable/shippable.sh @@ -90,6 +90,8 @@ function cleanup for file in test/results/reports/coverage=*.xml; do flags="${file##*/coverage=}" flags="${flags%.xml}" + # remove numbered component from stub files when converting to tags + flags="${flags//stub-[0-9]*/stub}" flags="${flags//=/,}" flags="${flags//[^a-zA-Z0-9_,]/_}"