Skip to content

Commit 3977a99

Browse files
committed
fixed bazel-contrib#221 - ci test run will print to stdout every 1 minute
1 parent 6bef36c commit 3977a99

File tree

2 files changed

+95
-34
lines changed

2 files changed

+95
-34
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ before_install:
3636
- cat .bazelrc.travis >> .bazelrc
3737

3838
script:
39-
- bash test_run.sh
39+
- bash test_run.sh ci

test_run.sh

Lines changed: 94 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,64 @@ test_benchmark_jmh() {
100100
fi
101101
exit $RESPONSE_CODE
102102
}
103+
103104
NC='\033[0m'
104105
GREEN='\033[0;32m'
105106
RED='\033[0;31m'
107+
TIMOUT=60
108+
109+
run_test_ci() {
110+
# spawns the test to new process
111+
local TEST_ARG=$@
112+
local log_file=output_$$.log
113+
echo "running test $TEST_ARG"
114+
$TEST_ARG &>$log_file &
115+
local test_pid=$!
116+
SECONDS=0
117+
test_pulse_printer $! $TIMOUT $TEST_ARG &
118+
local pulse_printer_pid=$!
119+
local result
120+
121+
{
122+
wait $test_pid 2>/dev/null
123+
result=$?
124+
kill $pulse_printer_pid && wait $pulse_printer_pid 2>/dev/null || true
125+
} || return 1
126+
127+
DURATION=$SECONDS
128+
if [ $result -eq 0 ]; then
129+
echo -e "\n${GREEN}Test \"$TEST_ARG\" successful ($DURATION sec) $NC"
130+
else
131+
echo -e "\nLog:\n"
132+
cat $log_file
133+
echo -e "\n${RED}Test \"$TEST_ARG\" failed $NC ($DURATION sec) $NC"
134+
fi
135+
return $result
136+
}
106137

107-
function run_test() {
138+
test_pulse_printer() {
139+
# makes sure something is printed to stdout while test is running
140+
local test_pid=$1
141+
shift
142+
local timeout=$1 # in minutes
143+
shift
144+
local count=0
145+
146+
# clear the line
147+
echo -e "\n"
148+
149+
while [ $count -lt $timeout ]; do
150+
count=$(($count + 1))
151+
echo -ne "Still running: \"$@\"\r"
152+
sleep 60
153+
done
154+
155+
echo -e "\n${RED}Timeout (${timeout} minutes) reached. Terminating \"$@\"${NC}\n"
156+
kill -9 $test_pid
157+
}
158+
159+
run_test_local() {
160+
# runs the tests locally
108161
set +e
109162
SECONDS=0
110163
TEST_ARG=$@
@@ -113,10 +166,11 @@ function run_test() {
113166
RESPONSE_CODE=$?
114167
DURATION=$SECONDS
115168
if [ $RESPONSE_CODE -eq 0 ]; then
116-
echo -e "${GREEN} Test $TEST_ARG successful ($DURATION sec) $NC"
169+
echo -e "${GREEN} Test \"$TEST_ARG\" successful ($DURATION sec) $NC"
117170
else
171+
echo -e "\nLog:\n"
118172
echo "$RES"
119-
echo -e "${RED} Test $TEST_ARG failed $NC ($DURATION sec) $NC"
173+
echo -e "${RED} Test \"$TEST_ARG\" failed $NC ($DURATION sec) $NC"
120174
exit $RESPONSE_CODE
121175
fi
122176
}
@@ -261,33 +315,40 @@ scala_junit_test_test_filter(){
261315
done
262316
}
263317

264-
run_test bazel build test/...
265-
run_test bazel test test/...
266-
run_test bazel run test/src/main/scala/scala/test/twitter_scrooge:justscrooges
267-
run_test bazel run test:JavaBinary
268-
run_test bazel run test:JavaBinary2
269-
run_test bazel run test:MixJavaScalaLibBinary
270-
run_test bazel run test:MixJavaScalaSrcjarLibBinary
271-
run_test bazel run test:ScalaBinary
272-
run_test bazel run test:ScalaLibBinary
273-
run_test test_disappearing_class
274-
run_test find -L ./bazel-testlogs -iname "*.xml"
275-
run_test xmllint_test
276-
run_test test_build_is_identical
277-
run_test test_transitive_deps
278-
run_test test_scala_library_suite
279-
run_test test_repl
280-
run_test bazel run test:JavaOnlySources
281-
run_test test_benchmark_jmh
282-
run_test multiple_junit_suffixes
283-
run_test multiple_junit_prefixes
284-
run_test test_scala_junit_test_can_fail
285-
run_test junit_generates_xml_logs
286-
run_test multiple_junit_patterns
287-
run_test test_junit_test_must_have_prefix_or_suffix
288-
run_test test_junit_test_errors_when_no_tests_found
289-
run_test scala_library_jar_without_srcs_must_include_direct_file_resources
290-
run_test scala_library_jar_without_srcs_must_include_filegroup_resources
291-
run_test bazel run test/src/main/scala/scala/test/large_classpath:largeClasspath
292-
run_test scala_test_test_filters
293-
run_test scala_junit_test_test_filter
318+
319+
if [ "$1" != "ci" ]; then
320+
runner="run_test_local"
321+
else
322+
runner="run_test_ci"
323+
fi
324+
325+
$runner bazel build test/...
326+
$runner bazel test test/...
327+
$runner bazel run test/src/main/scala/scala/test/twitter_scrooge:justscrooges
328+
$runner bazel run test:JavaBinary
329+
$runner bazel run test:JavaBinary2
330+
$runner bazel run test:MixJavaScalaLibBinary
331+
$runner bazel run test:MixJavaScalaSrcjarLibBinary
332+
$runner bazel run test:ScalaBinary
333+
$runner bazel run test:ScalaLibBinary
334+
$runner test_disappearing_class
335+
$runner find -L ./bazel-testlogs -iname "*.xml"
336+
$runner xmllint_test
337+
$runner test_build_is_identical
338+
$runner test_transitive_deps
339+
$runner test_scala_library_suite
340+
$runner test_repl
341+
$runner bazel run test:JavaOnlySources
342+
$runner test_benchmark_jmh
343+
$runner multiple_junit_suffixes
344+
$runner multiple_junit_prefixes
345+
$runner test_scala_junit_test_can_fail
346+
$runner junit_generates_xml_logs
347+
$runner multiple_junit_patterns
348+
$runner test_junit_test_must_have_prefix_or_suffix
349+
$runner test_junit_test_errors_when_no_tests_found
350+
$runner scala_library_jar_without_srcs_must_include_direct_file_resources
351+
$runner scala_library_jar_without_srcs_must_include_filegroup_resources
352+
$runner bazel run test/src/main/scala/scala/test/large_classpath:largeClasspath
353+
$runner scala_test_test_filters
354+
$runner scala_junit_test_test_filter

0 commit comments

Comments
 (0)