Skip to content

Commit 45441d8

Browse files
committed
dev/tests: run tests in groups
To improve performance and reduce memory usage, run tests in batches of 20.
1 parent 46ad5ec commit 45441d8

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

flake/dev/launch-test.sh

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ Options:
1818
-h, --help: Display this help message and exit
1919
-l, --list: Display the list of tests and exit
2020
-s, --system <system>: Launch checks for "<system>" instead of "${NIXVIM_SYSTEM}".
21+
-g, --group-size N: The maximum number of tests to build at once. Default 20.
2122
-i, --interactive: Pick interactively the tests. Can't be supplied if tests where passed.
2223
-a, --attr: Print full attrpath of the tests, instead of running them.
2324
EOF
2425
}
2526

26-
if ! OPTS=$(getopt -o "hlis:a" -l "help,list,interactive,system:,attr" -- "$@"); then
27+
if ! OPTS=$(getopt -o "hlis:g:a" -l "help,list,interactive,system:,group-size:,attr" -- "$@"); then
2728
echo "Invalid options" >&2
2829
help
2930
exit 1
@@ -35,6 +36,7 @@ system=${NIXVIM_SYSTEM}
3536
specified_tests=()
3637
nix_args=()
3738
interactive=false
39+
group_size=20
3840
print_attrpath=false
3941

4042
mk_test_list() {
@@ -55,6 +57,10 @@ while true; do
5557
interactive=true
5658
shift
5759
;;
60+
-g | --group-size)
61+
group_size=$2
62+
shift 2
63+
;;
5864
-s | --system)
5965
system=$2
6066
shift 2
@@ -94,6 +100,50 @@ get_tests() {
94100
done
95101
}
96102

103+
build_group() {
104+
if ! "${NIXVIM_NIX_COMMAND}" build "${nix_args[@]}" --no-link --file . "$@"; then
105+
echo "Test failure" >&2
106+
return 1
107+
fi
108+
}
109+
110+
build_in_groups() {
111+
# Count failures
112+
failures=0
113+
114+
# $@ is weird and sometimes includes the script's filename, othertimes doesn't.
115+
# Copying it to a normal array results in a consistent behaviour.
116+
tests=("$@")
117+
test_count=${#tests[@]}
118+
119+
# Calculate how many groups we need
120+
if ((group_size > test_count)); then
121+
group_size=$test_count
122+
fi
123+
group_count=$((test_count / group_size))
124+
125+
for ((group_idx = 0; group_idx <= group_count; group_idx++)); do
126+
# The index pointing to the start of the group slice
127+
start_idx=$((group_idx * group_size))
128+
129+
if ((group_idx == group_count)); then
130+
group_slice=("${tests[@]:start_idx}")
131+
else
132+
group_slice=("${tests[@]:start_idx:group_size}")
133+
fi
134+
135+
if ((group_count > 1)); then
136+
echo "Building group $group_idx of $group_count"
137+
fi
138+
139+
if ! build_group "${group_slice[@]}"; then
140+
((++failures))
141+
fi
142+
done
143+
144+
((failures == 0))
145+
}
146+
97147
run_tests() {
98148
readarray -t test_list < <(get_tests "$@")
99149
if [[ $print_attrpath == true ]]; then
@@ -102,7 +152,7 @@ run_tests() {
102152
for test in "${test_list[@]}"; do
103153
echo "- $test"
104154
done
105-
elif ! "${NIXVIM_NIX_COMMAND}" build "${nix_args[@]}" --no-link --file . "${test_list[@]}"; then
155+
elif ! build_in_groups "${test_list[@]}"; then
106156
echo "Test failure" >&2
107157
exit 1
108158
fi

0 commit comments

Comments
 (0)