Skip to content

Commit 70b9924

Browse files
Shareable function for partitioning integration tests (#17223) (#17304)
For the fedramp high work https://github.com/elastic/logstash/pull/17038/files a use case for multiple scripts consuming the partitioning functionality emerged. As we look to more advanced partitioning we want to ensure that the functionality will be consumable from multiple scripts. See #17219 (comment) (cherry picked from commit d916972) Co-authored-by: Cas Donoghue <[email protected]>
1 parent 7bc0194 commit 70b9924

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

Diff for: ci/get-test-half.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# get_test_half returns either the first or second half of integration tests
4+
# Usage: get_test_half <half_number>
5+
# half_number: 0 for first half, 1 for second half
6+
get_test_half() {
7+
local half_number=$1
8+
# Ensure only spec files go to stdout
9+
pushd qa/integration >/dev/null 2>&1
10+
11+
# Collect all spec files
12+
local glob1=(specs/*spec.rb)
13+
local glob2=(specs/**/*spec.rb)
14+
local all_specs=("${glob1[@]}" "${glob2[@]}")
15+
16+
# Calculate the split point
17+
local split_point=$((${#all_specs[@]} / 2))
18+
19+
# Get the requested half (:: is "up to", : is "from")
20+
if [[ $half_number -eq 0 ]]; then
21+
local specs="${all_specs[@]::$split_point}"
22+
else
23+
local specs="${all_specs[@]:$split_point}"
24+
fi
25+
popd >/dev/null 2>&1
26+
echo "$specs"
27+
}

Diff for: ci/integration_tests.sh

+7-14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export SPEC_OPTS="--order rand --format documentation"
1111
export CI=true
1212
export OSS=true
1313

14+
# Source shared function for splitting integration tests
15+
source "$(dirname "${BASH_SOURCE[0]}")/get-test-half.sh"
16+
1417
if [ -n "$BUILD_JAVA_HOME" ]; then
1518
GRADLE_OPTS="$GRADLE_OPTS -Dorg.gradle.java.home=$BUILD_JAVA_HOME"
1619
fi
@@ -20,20 +23,10 @@ if [[ $1 = "setup" ]]; then
2023
exit 0
2124

2225
elif [[ $1 == "split" ]]; then
23-
cd qa/integration
24-
glob1=(specs/*spec.rb)
25-
glob2=(specs/**/*spec.rb)
26-
all_specs=("${glob1[@]}" "${glob2[@]}")
27-
28-
specs0=${all_specs[@]::$((${#all_specs[@]} / 2 ))}
29-
specs1=${all_specs[@]:$((${#all_specs[@]} / 2 ))}
30-
cd ../..
31-
if [[ $2 == 0 ]]; then
32-
echo "Running the first half of integration specs: $specs0"
33-
./gradlew runIntegrationTests -PrubyIntegrationSpecs="$specs0" --console=plain
34-
elif [[ $2 == 1 ]]; then
35-
echo "Running the second half of integration specs: $specs1"
36-
./gradlew runIntegrationTests -PrubyIntegrationSpecs="$specs1" --console=plain
26+
if [[ $2 =~ ^[01]$ ]]; then
27+
specs=$(get_test_half "$2")
28+
echo "Running half $2 of integration specs: $specs"
29+
./gradlew runIntegrationTests -PrubyIntegrationSpecs="$specs" --console=plain
3730
else
3831
echo "Error, must specify 0 or 1 after the split. For example ci/integration_tests.sh split 0"
3932
exit 1

0 commit comments

Comments
 (0)