Skip to content

Commit

Permalink
slice /per-rule non-sequentially
Browse files Browse the repository at this point in the history
This is to make each /per-rule/N runner get a more diverse
slice of all tests.

Signed-off-by: Jiri Jaburek <[email protected]>
  • Loading branch information
comps committed Apr 26, 2024
1 parent 1506bcf commit 828eedb
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions per-rule/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,6 @@
from conf import partitions


def slice_list(full_list, divident, divisor):
"""
Slice a 'full_list' into approx. equally-sized 'divisor' parts,
return the 'divident' slice.
"""
total = len(full_list)
quotient = int(total / divisor)
remainder = total % divisor
# add 1 to the first dividents, up until all the added 1s
# are consumed (they add up to a value equal to remainder)
count = quotient + (1 if remainder >= divident else 0)
# starting index, from 0, with remainder gradually added,
# capped by max remainder value
start = (divident-1)*quotient + min(remainder, (divident-1))
# end = start of current slice + amount
# (as last valid index + 1, for python slice end)
end = start + count
# return a slice of the original list rather than copying it
return full_list[start:end]


def between_strings(full_text, before, after):
"""
Cut off a middle section of a 'full_text' string between the
Expand Down Expand Up @@ -76,11 +55,14 @@ def report_test_with_log(status, note, log_dir, rule_name, test_name):
else:
raise RuntimeError("RULE env variable not defined or empty")
else:
our_rules = slice_list(
sorted(oscap.global_ds().get_all_profiles_rules()),
int(test_basename),
int(os.environ['TOTAL_SLICES'])
)
all_rules = sorted(oscap.global_ds().get_all_profiles_rules())
start = int(test_basename) - 1
total = int(os.environ['TOTAL_SLICES'])
# slice all_rules, get every total-th member
our_rules = all_rules[start::total]

if not our_rules:
raise RuntimeError("no rules to test")

if fix_type == 'ansible':
ansible.install_deps()
Expand Down

0 comments on commit 828eedb

Please sign in to comment.