Skip to content

Commit f08d8d6

Browse files
committed
when on OSX, use all relevant nc timeout options
1 parent d101d61 commit f08d8d6

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

wait-for

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,21 @@ USAGE
3030
exit "$exitcode"
3131
}
3232

33+
test_connection() {
34+
# force a 1-second timeout on darwin (https://stackoverflow.com/a/20460402/2063546)
35+
# POSIX-compliant string inclusion test https://stackoverflow.com/a/8811800/2063546
36+
if [ "${OSTYPE#*darwin*}" != "$OSTYPE" ] ; then
37+
nc -z -w 1 -G 1 "$1" "$2"
38+
else
39+
nc -z -w 1 "$1" "$2" > /dev/null 2>&1
40+
fi
41+
}
42+
3343
wait_for() {
3444
for i in `seq $TIMEOUT` ; do
35-
# use a 1-second timeout
36-
nc -w 1 -z "$HOST" "$PORT" > /dev/null 2>&1
37-
45+
# use a 1-second timeout, but still sleep 0.1 seconds after just to be safe
46+
test_connection "$HOST" "$PORT"
47+
3848
result=$?
3949
if [ $result -eq 0 ] ; then
4050
if [ $# -gt 0 ] ; then

0 commit comments

Comments
 (0)