-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
run_unit_group.sh
executable file
·233 lines (207 loc) · 8.75 KB
/
run_unit_group.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
set -e
set -o pipefail
set -o errexit
MVN_TEST_OPTIONS='mvn -B -ntp -DskipSourceReleaseAssembly=true -DskipBuildDistribution=true -Dspotbugs.skip=true -Dlicense.skip=true -Dcheckstyle.skip=true -Drat.skip=true'
function mvn_test() {
(
local clean_arg=""
if [[ "$1" == "--clean" ]]; then
clean_arg="clean"
shift
fi
local coverage_arg="-Pcoverage"
if [[ "${COLLECT_COVERAGE}" == "false" ]]; then
coverage_arg=""
fi
local target="verify"
if [[ "$1" == "--install" ]]; then
target="install"
shift
fi
local use_fail_fast=1
if [[ "$GITHUB_ACTIONS" == "true" && "$GITHUB_EVENT_NAME" != "pull_request" ]]; then
use_fail_fast=0
fi
if [[ "$1" == "--no-fail-fast" ]]; then
use_fail_fast=0
shift;
fi
local failfast_args
if [ $use_fail_fast -eq 1 ]; then
failfast_args="-DtestFailFast=true -DtestFailFastFile=/tmp/test_fail_fast_killswitch.$$.$RANDOM.$(date +%s) --fail-fast"
else
failfast_args="-DtestFailFast=false --fail-at-end"
fi
echo "::group::Run tests for " "$@"
# use "verify" instead of "test" to workaround MDEP-187 issue in pulsar-functions-worker and pulsar-broker projects with the maven-dependency-plugin's copy goal
# Error message was "Artifact has not been packaged yet. When used on reactor artifact, copy should be executed after packaging: see MDEP-187"
$MVN_TEST_OPTIONS $failfast_args $clean_arg $target $coverage_arg "$@" "${COMMANDLINE_ARGS[@]}"
echo "::endgroup::"
set +x
"$SCRIPT_DIR/pulsar_ci_tool.sh" move_test_reports
)
}
# solution for printing output in "set -x" trace mode without tracing the echo calls
shopt -s expand_aliases
echo_and_restore_trace() {
builtin echo "$@"
[ $trace_enabled -eq 1 ] && set -x || true
}
alias echo='{ [[ $- =~ .*x.* ]] && trace_enabled=1 || trace_enabled=0; set +x; } 2> /dev/null; echo_and_restore_trace'
# Test Groups -- start --
function test_group_broker_group_1() {
mvn_test -pl pulsar-broker -Dgroups='broker' -DtestReuseFork=true
}
function test_group_broker_group_2() {
mvn_test -pl pulsar-broker -Dgroups='schema,utils,functions-worker,broker-io,broker-discovery,broker-compaction,broker-naming,websocket,other'
}
function test_group_broker_group_3() {
mvn_test -pl pulsar-broker -Dgroups='broker-admin'
}
function test_group_broker_client_api() {
mvn_test -pl pulsar-broker -Dgroups='broker-api'
}
function test_group_broker_client_impl() {
mvn_test -pl pulsar-broker -Dgroups='broker-impl'
}
function test_group_client() {
mvn_test -pl pulsar-client
}
# prints summaries of failed tests to console
# by using the targer/surefire-reports files
# works only when testForkCount > 1 since that is when surefire will create reports for individual test classes
function print_testng_failures() {
(
{ set +x; } 2>/dev/null
local testng_failed_file="$1"
local report_prefix="${2:-Test failure in}"
local group_title="${3:-Detailed test failures}"
if [ -f "$testng_failed_file" ]; then
local testng_report_dir=$(dirname "$testng_failed_file")
local failed_count=0
for failed_test_class in $(cat "$testng_failed_file" | grep 'class name=' | perl -p -e 's/.*\"(.*?)\".*/$1/'); do
((failed_count += 1))
if [ $failed_count -eq 1 ]; then
echo "::endgroup::"
echo "::group::${group_title}"
fi
local test_report_file="${testng_report_dir}/${failed_test_class}.txt"
if [ -f "${test_report_file}" ]; then
local test_report="$(cat "${test_report_file}" | grep -E "^Tests run: " | perl -p -se 's/^(Tests run: .*) <<< FAILURE! - in (.*)$/::warning::$report_prefix $2 - $1/' -- -report_prefix="${report_prefix}")"
echo "$test_report"
cat "${test_report_file}"
fi
done
fi
)
}
function test_group_broker_flaky() {
echo "::endgroup::"
echo "::group::Running quarantined tests"
mvn_test --no-fail-fast -pl pulsar-broker -Dgroups='quarantine' -DexcludedGroups='' -DfailIfNoTests=false \
-DtestForkCount=2 ||
print_testng_failures pulsar-broker/target/surefire-reports/testng-failed.xml "Quarantined test failure in" "Quarantined test failures"
echo "::endgroup::"
echo "::group::Running flaky tests"
mvn_test --no-fail-fast -pl pulsar-broker -Dgroups='flaky' -DtestForkCount=2
echo "::endgroup::"
}
function test_group_proxy() {
echo "::group::Running pulsar-proxy tests"
mvn_test -pl pulsar-proxy -Dtest="org.apache.pulsar.proxy.server.ProxyServiceTlsStarterTest"
mvn_test -pl pulsar-proxy -Dtest="org.apache.pulsar.proxy.server.ProxyServiceStarterTest"
mvn_test -pl pulsar-proxy -Dexclude='org.apache.pulsar.proxy.server.ProxyServiceTlsStarterTest,
org.apache.pulsar.proxy.server.ProxyServiceStarterTest'
echo "::endgroup::"
}
function test_group_other() {
mvn_test --clean --install \
-pl '!org.apache.pulsar:distribution,!org.apache.pulsar:pulsar-offloader-distribution,!org.apache.pulsar:pulsar-server-distribution,!org.apache.pulsar:pulsar-io-distribution,!org.apache.pulsar:pulsar-all-docker-image' \
-PskipTestsForUnitGroupOther -DdisableIoMainProfile=true -DdisableSqlMainProfile=true -DskipIntegrationTests \
-Dexclude='**/ManagedLedgerTest.java,
**/OffloadersCacheTest.java
**/PrimitiveSchemaTest.java,
**/BlobStoreManagedLedgerOffloaderTest.java,
**/BlobStoreManagedLedgerOffloaderStreamingTest.java'
mvn_test -pl managed-ledger -Dinclude='**/ManagedLedgerTest.java,
**/OffloadersCacheTest.java'
mvn_test -pl tiered-storage/jcloud -Dinclude='**/BlobStoreManagedLedgerOffloaderTest.java'
mvn_test -pl tiered-storage/jcloud -Dinclude='**/BlobStoreManagedLedgerOffloaderStreamingTest.java'
echo "::endgroup::"
local modules_with_quarantined_tests=$(git grep -l '@Test.*"quarantine"' | grep '/src/test/java/' | \
awk -F '/src/test/java/' '{ print $1 }' | grep -v -E 'pulsar-broker|pulsar-proxy|pulsar-io|pulsar-sql|pulsar-client' | sort | uniq | \
perl -0777 -p -e 's/\n(\S)/,$1/g')
if [ -n "${modules_with_quarantined_tests}" ]; then
echo "::group::Running quarantined tests outside of pulsar-broker & pulsar-proxy (if any)"
mvn_test --no-fail-fast -pl "${modules_with_quarantined_tests}" test -Dgroups='quarantine' -DexcludedGroups='' \
-DfailIfNoTests=false || \
echo "::warning::There were test failures in the 'quarantine' test group."
echo "::endgroup::"
fi
}
function test_group_pulsar_io() {
echo "::group::Running pulsar-io tests"
mvn_test --install -Ppulsar-io-tests,-main
echo "::endgroup::"
echo "::group::Running pulsar-sql tests"
mvn_test --install -Ppulsar-sql-tests,-main -DtestForkCount=1
echo "::endgroup::"
}
function test_group_pulsar_io_elastic() {
echo "::group::Running elastic-search tests"
mvn_test --install -Ppulsar-io-elastic-tests,-main
echo "::endgroup::"
}
function test_group_pulsar_io_kafka_connect() {
echo "::group::Running Pulsar IO Kafka connect adaptor tests"
mvn_test --install -Ppulsar-io-kafka-connect-tests,-main
echo "::endgroup::"
}
function list_test_groups() {
declare -F | awk '{print $NF}' | sort | grep -E '^test_group_' | sed 's/^test_group_//g' | tr '[:lower:]' '[:upper:]'
}
# Test Groups -- end --
if [[ "$1" == "--list" ]]; then
list_test_groups
exit 0
fi
TEST_GROUP=$1
if [ -z "$TEST_GROUP" ]; then
echo "usage: $0 [test_group]"
echo "Available test groups:"
list_test_groups
exit 1
fi
shift
COMMANDLINE_ARGS=("$@")
echo "Test Group : $TEST_GROUP"
test_group_function_name="test_group_$(echo "$TEST_GROUP" | tr '[:upper:]' '[:lower:]')"
if [[ "$(LC_ALL=C type -t "${test_group_function_name}")" == "function" ]]; then
set -x
eval "$test_group_function_name"
else
echo "INVALID TEST GROUP"
echo "Available test groups:"
list_test_groups
exit 1
fi