Skip to content

Commit 008d6ea

Browse files
hhorakphracek
authored andcommitted
Use timeout utility instead of double-sub-shell hell
It turned out that for incremental builds for Node.js, the test always waited 10m no matter that the build finished sooner. It's not clear why it happened, but when debugging, it seemed like some weired race-condition happened that let some sleeps hang. Anyway, it's not clear whether there is a reason to not use timeout utility that seems to serve exactly for this reason.
1 parent cb3fdd3 commit 008d6ea

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

test-lib.sh

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,14 @@ ct_build_image_and_parse_id() {
7474
local ret_val
7575
local dockerfile
7676
local command
77-
local pid_build
78-
local pid_sleep
7977
local sleep_time
8078
log_file="$(mktemp)"
8179
sleep_time="10m"
8280
[ -n "$1" ] && dockerfile="-f $1"
8381
command="$(echo "docker build --no-cache $dockerfile $2" | tr -d "'")"
84-
# running command in subshell, the subshell in background, storing pid to variable
85-
(
86-
$command > "$log_file" 2>&1
87-
) & pid_build=$!
88-
# creating second subshell with trap function on ALRM signal
89-
# the subshell sleeps for 10m, then kills the first subshell
90-
(
91-
trap 'exit 0' ALRM; sleep "$sleep_time" && kill $pid_build
92-
) & pid_sleep=$!
93-
# waiting for build subshell to finish, either with success, or killed from sleep subshell
94-
wait $pid_build
82+
# shellcheck disable=SC2086
83+
timeout $sleep_time $command > "$log_file" 2>&1
9584
ret_val=$?
96-
# send ALRM signal to the sleep subshell, so it exits even in case the 10mins
97-
# not yet passed. If the kill was successful (the wait subshell received ALRM signal)
98-
# then the build was not finished yet, so the return value is set to 1
99-
kill -s ALRM $pid_sleep 2>/dev/null || ret_val=1
100-
10185
if [ $ret_val -eq 0 ]; then
10286
APP_IMAGE_ID="$(tail -n 1 "$log_file")"
10387
fi

0 commit comments

Comments
 (0)