Skip to content

Commit 12c2094

Browse files
committed
fix bazel-contrib#221 - prints to stdout every 1 minutes
1 parent a94b6d0 commit 12c2094

File tree

2 files changed

+89
-31
lines changed

2 files changed

+89
-31
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: 88 additions & 30 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+
echo $@
112+
local cmd=$@
113+
local log_file=output_$$.log
114+
115+
$cmd &>$log_file &
116+
local cmd_pid=$!
117+
118+
jigger $! $TIMOUT $cmd &
119+
local jigger_pid=$!
120+
local result
106121

107-
function run_test() {
122+
{
123+
wait $cmd_pid 2>/dev/null
124+
result=$?
125+
ps -p$jigger_pid &>/dev/null && kill $jigger_pid
126+
} || return 1
127+
128+
if [ $result -eq 0 ]; then
129+
echo -e "\n${GREEN}The command \"$cmd\" exited with $result.${NC}"
130+
else
131+
echo -e "\n${RED}The command \"$cmd\" exited with $result.${NC}"
132+
echo -e "\nLog:\n"
133+
cat $log_file
134+
fi
135+
return $result
136+
}
137+
138+
jigger() {
139+
# makes sure something is printed to stdout while process is running
140+
local cmd_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 "$(date): Still running: $@\r"
152+
sleep 60
153+
done
154+
155+
echo -e "\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"$@\"${ANSI_RESET}\n"
156+
kill -9 $cmd_pid
157+
}
158+
159+
run_test_local() {
160+
# runs the tests locally
108161
set +e
109162
SECONDS=0
110163
TEST_ARG=$@
@@ -226,33 +279,38 @@ scala_test_test_filters() {
226279
fi
227280
}
228281

282+
if [ "$1" != "ci" ]; then
283+
runner="run_test_local"
284+
else
285+
runner="run_test_ci"
286+
fi
229287

230-
run_test bazel build test/...
231-
run_test bazel test test/...
232-
run_test bazel run test/src/main/scala/scala/test/twitter_scrooge:justscrooges
233-
run_test bazel run test:JavaBinary
234-
run_test bazel run test:JavaBinary2
235-
run_test bazel run test:MixJavaScalaLibBinary
236-
run_test bazel run test:MixJavaScalaSrcjarLibBinary
237-
run_test bazel run test:ScalaBinary
238-
run_test bazel run test:ScalaLibBinary
239-
run_test test_disappearing_class
240-
run_test find -L ./bazel-testlogs -iname "*.xml"
241-
run_test xmllint_test
242-
run_test test_build_is_identical
243-
run_test test_transitive_deps
244-
run_test test_scala_library_suite
245-
run_test test_repl
246-
run_test bazel run test:JavaOnlySources
247-
run_test test_benchmark_jmh
248-
run_test multiple_junit_suffixes
249-
run_test multiple_junit_prefixes
250-
run_test test_scala_junit_test_can_fail
251-
run_test junit_generates_xml_logs
252-
run_test multiple_junit_patterns
253-
run_test test_junit_test_must_have_prefix_or_suffix
254-
run_test test_junit_test_errors_when_no_tests_found
255-
run_test scala_library_jar_without_srcs_must_include_direct_file_resources
256-
run_test scala_library_jar_without_srcs_must_include_filegroup_resources
257-
run_test bazel run test/src/main/scala/scala/test/large_classpath:largeClasspath
258-
run_test scala_test_test_filters
288+
$runner bazel build test/...
289+
$runner bazel test test/...
290+
$runner bazel run test/src/main/scala/scala/test/twitter_scrooge:justscrooges
291+
$runner bazel run test:JavaBinary
292+
$runner bazel run test:JavaBinary2
293+
$runner bazel run test:MixJavaScalaLibBinary
294+
$runner bazel run test:MixJavaScalaSrcjarLibBinary
295+
$runner bazel run test:ScalaBinary
296+
$runner bazel run test:ScalaLibBinary
297+
$runner test_disappearing_class
298+
$runner find -L ./bazel-testlogs -iname "*.xml"
299+
$runner xmllint_test
300+
$runner test_build_is_identical
301+
$runner test_transitive_deps
302+
$runner test_scala_library_suite
303+
$runner test_repl
304+
$runner bazel run test:JavaOnlySources
305+
$runner test_benchmark_jmh
306+
$runner multiple_junit_suffixes
307+
$runner multiple_junit_prefixes
308+
$runner test_scala_junit_test_can_fail
309+
$runner junit_generates_xml_logs
310+
$runner multiple_junit_patterns
311+
$runner test_junit_test_must_have_prefix_or_suffix
312+
$runner test_junit_test_errors_when_no_tests_found
313+
$runner scala_library_jar_without_srcs_must_include_direct_file_resources
314+
$runner scala_library_jar_without_srcs_must_include_filegroup_resources
315+
$runner bazel run test/src/main/scala/scala/test/large_classpath:largeClasspath
316+
$runner scala_test_test_filters

0 commit comments

Comments
 (0)