forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_unit_group.sh
executable file
·186 lines (154 loc) · 6.19 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
#!/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.
#
set -e
set -o pipefail
set -o errexit
# 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'
MVN_COMMAND='mvn -B -ntp'
MVN_COMMAND_WITH_RETRY="build/retry.sh ${MVN_COMMAND}"
MVN_TEST_COMMAND="${MVN_COMMAND_WITH_RETRY} test"
echo -n "Test Group : $TEST_GROUP"
# Test Groups -- start --
function broker_group_1() {
$MVN_TEST_COMMAND -pl pulsar-broker -Dgroups='broker'
}
function broker_group_2() {
$MVN_TEST_COMMAND -pl pulsar-broker -Dgroups='schema,utils,functions-worker,broker-io,broker-discovery,broker-compaction,broker-naming,websocket,other'
}
function broker_client_api() {
$MVN_TEST_COMMAND -pl pulsar-broker -Dgroups='broker-api'
}
function broker_client_impl() {
$MVN_TEST_COMMAND -pl pulsar-broker -Dgroups='broker-impl'
}
function broker_jdk8() {
$MVN_TEST_COMMAND -pl pulsar-broker -Dgroups='broker-jdk8' -Dpulsar.allocator.pooled=true
}
# 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}" | egrep "^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 broker_flaky() {
echo "::endgroup::"
echo "::group::Running quarantined tests"
$MVN_COMMAND test -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_COMMAND -pl pulsar-broker -Dgroups='flaky' -DtestForkCount=2
echo "::endgroup::"
}
function proxy() {
echo "::group::Running pulsar-proxy tests"
$MVN_TEST_COMMAND -pl pulsar-proxy -Dtest="org.apache.pulsar.proxy.server.ProxyServiceTlsStarterTest"
$MVN_TEST_COMMAND -pl pulsar-proxy -Dtest="org.apache.pulsar.proxy.server.ProxyServiceStarterTest"
$MVN_TEST_COMMAND -pl pulsar-proxy -Dexclude='org.apache.pulsar.proxy.server.ProxyServiceTlsStarterTest,
org.apache.pulsar.proxy.server.ProxyServiceStarterTest'
echo "::endgroup::"
}
function other() {
$MVN_COMMAND_WITH_RETRY clean install -PbrokerSkipTest \
-Dexclude='org/apache/pulsar/proxy/**/*.java,
**/ManagedLedgerTest.java,
**/TestPulsarKeyValueSchemaHandler.java,
**/PrimitiveSchemaTest.java,
BlobStoreManagedLedgerOffloaderTest.java'
$MVN_TEST_COMMAND -pl managed-ledger -Dinclude='**/ManagedLedgerTest.java,
**/OffloadersCacheTest.java'
$MVN_TEST_COMMAND -pl pulsar-sql/presto-pulsar-plugin -Dinclude='**/TestPulsarKeyValueSchemaHandler.java'
$MVN_TEST_COMMAND -pl pulsar-client -Dinclude='**/PrimitiveSchemaTest.java'
$MVN_TEST_COMMAND -pl tiered-storage/jcloud -Dinclude='**/BlobStoreManagedLedgerOffloaderTest.java'
echo "::endgroup::"
local modules_with_quarantined_tests=$(git grep -l '@Test.*"quarantine"' | grep '/src/test/java/' | \
awk -F '/src/test/java/' '{ print $1 }' | egrep -v 'pulsar-broker|pulsar-proxy' | 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_COMMAND -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
}
# Test Groups -- end --
TEST_GROUP=$1
echo "Test Group : $TEST_GROUP"
set -x
case $TEST_GROUP in
BROKER_GROUP_1)
broker_group_1
;;
BROKER_GROUP_2)
broker_group_2
;;
BROKER_CLIENT_API)
broker_client_api
;;
BROKER_CLIENT_IMPL)
broker_client_impl
;;
BROKER_FLAKY)
broker_flaky
;;
PROXY)
proxy
;;
OTHER)
other
;;
BROKER_JDK8)
broker_jdk8
;;
*)
echo -n "INVALID TEST GROUP"
exit 1
;;
esac