From 45a8428a30c2aebeb5163913c8167b318ff65c81 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 31 Dec 2022 07:34:10 +0100 Subject: tests: rework common code Turn try-ssh.sh script into a shell function library. --- tests/test_common.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/test_common.sh (limited to 'tests/test_common.sh') diff --git a/tests/test_common.sh b/tests/test_common.sh new file mode 100644 index 0000000..f42a26a --- /dev/null +++ b/tests/test_common.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +run_ssh() { + test -n "${SSH_KEYPATH:-}" && set -- -i "$SSH_KEYPATH" "$@" + test -n "${SSH_PORT:-}" && set -- -p "$SSH_PORT" "$@" + ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -l root "$@" +} + +wait_ssh() { + wait_ssh_timeout=5 + wait_ssh_ts=$(sleepenh 0 || [ $? -eq 1 ]) + for _ in $(seq 30); do + run_ssh -o ConnectTimeout="$wait_ssh_timeout" "$@" echo success && return 0 + wait_ssh_ts=$(sleepenh "$wait_ssh_ts" "$wait_ssh_timeout" || [ $? -eq 1 ]) + done + echo "timeout reached" >&2 + return 1 +} -- cgit v1.2.3