Skip to content

Commit ce7774e

Browse files
committed
regtest: add timeout to wait_ functions
Add 30s timeouts to the "wait_" functions in regtest.sh as it happens from time to time that they get stuck on the CI and waste compute.
1 parent 76f6967 commit ce7774e

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/regtest/regtest.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@ function wait_until_htlcs_settled()
2222
{
2323
msg="wait until $1's local_unsettled_sent is zero"
2424
cmd="./run_electrum --regtest -D /tmp/$1"
25+
declare -i timeout_sec=30
26+
declare -i elapsed_sec=0
27+
2528
while unsettled=$($cmd list_channels | jq '.[] | .local_unsettled_sent') && [ $unsettled != "0" ]; do
29+
if ((elapsed_sec > timeout_sec)); then
30+
printf "Timeout of %i s exceeded\n" "$elapsed_sec"
31+
exit 1
32+
fi
33+
2634
sleep 1
35+
elapsed_sec=$((elapsed_sec + 1))
2736
msg="$msg."
2837
printf "$msg\r"
2938
done
@@ -35,8 +44,17 @@ function wait_for_balance()
3544
{
3645
msg="wait until $1's balance reaches $2"
3746
cmd="./run_electrum --regtest -D /tmp/$1"
47+
declare -i timeout_sec=30
48+
declare -i elapsed_sec=0
49+
3850
while balance=$($cmd getbalance | jq '[.confirmed, .unconfirmed] | to_entries | map(select(.value != null).value) | map(tonumber) | add ') && (( $(echo "$balance < $2" | bc -l) )); do
51+
if ((elapsed_sec > timeout_sec)); then
52+
printf "Timeout of %i s exceeded\n" "$elapsed_sec"
53+
exit 1
54+
fi
55+
3956
sleep 1
57+
elapsed_sec=$((elapsed_sec + 1))
4058
msg="$msg."
4159
printf "$msg\r"
4260
done
@@ -47,8 +65,17 @@ function wait_until_channel_open()
4765
{
4866
msg="wait until $1 sees channel open"
4967
cmd="./run_electrum --regtest -D /tmp/$1"
68+
declare -i timeout_sec=30
69+
declare -i elapsed_sec=0
70+
5071
while channel_state=$($cmd list_channels | jq '.[0] | .state' | tr -d '"') && [ $channel_state != "OPEN" ]; do
72+
if ((elapsed_sec > timeout_sec)); then
73+
printf "Timeout of %i s exceeded\n" "$elapsed_sec"
74+
exit 1
75+
fi
76+
5177
sleep 1
78+
elapsed_sec=$((elapsed_sec + 1))
5279
msg="$msg."
5380
printf "$msg\r"
5481
done
@@ -59,8 +86,17 @@ function wait_until_channel_closed()
5986
{
6087
msg="wait until $1 sees channel closed"
6188
cmd="./run_electrum --regtest -D /tmp/$1"
89+
declare -i timeout_sec=30
90+
declare -i elapsed_sec=0
91+
6292
while [[ $($cmd list_channels | jq '.[0].state' | tr -d '"') != "CLOSED" ]]; do
93+
if ((elapsed_sec > timeout_sec)); then
94+
printf "Timeout of %i s exceeded\n" "$elapsed_sec"
95+
exit 1
96+
fi
97+
6398
sleep 1
99+
elapsed_sec=$((elapsed_sec + 1))
64100
msg="$msg."
65101
printf "$msg\r"
66102
done
@@ -71,8 +107,17 @@ function wait_until_preimage()
71107
{
72108
msg="wait until $1 has preimage for $2"
73109
cmd="./run_electrum --regtest -D /tmp/$1"
110+
declare -i timeout_sec=30
111+
declare -i elapsed_sec=0
112+
74113
while [[ $($cmd get_invoice $2 | jq '.preimage' | tr -d '"') == "null" ]]; do
114+
if ((elapsed_sec > timeout_sec)); then
115+
printf "Timeout of %i s exceeded\n" "$elapsed_sec"
116+
exit 1
117+
fi
118+
75119
sleep 1
120+
elapsed_sec=$((elapsed_sec + 1))
76121
msg="$msg."
77122
printf "$msg\r"
78123
done
@@ -82,8 +127,17 @@ function wait_until_preimage()
82127
function wait_until_spent()
83128
{
84129
msg="wait until $1:$2 is spent"
130+
declare -i timeout_sec=30
131+
declare -i elapsed_sec=0
132+
85133
while [[ $($bitcoin_cli gettxout $1 $2) ]]; do
134+
if ((elapsed_sec > timeout_sec)); then
135+
printf "Timeout of %i s exceeded\n" "$elapsed_sec"
136+
exit 1
137+
fi
138+
86139
sleep 1
140+
elapsed_sec=$((elapsed_sec + 1))
87141
msg="$msg."
88142
printf "$msg\r"
89143
done

0 commit comments

Comments
 (0)