From 7cc42503c1d894d7322d23d987a21c5148849104 Mon Sep 17 00:00:00 2001 From: vindard <17693119+vindard@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:22:26 -0400 Subject: [PATCH] test(core): remove trigger sleep --- bats/core/api/ln-receive.bats | 9 +++++---- bats/helpers/trigger.bash | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 bats/helpers/trigger.bash diff --git a/bats/core/api/ln-receive.bats b/bats/core/api/ln-receive.bats index ef72f98c4b7..fc7790d7d8b 100644 --- a/bats/core/api/ln-receive.bats +++ b/bats/core/api/ln-receive.bats @@ -6,12 +6,11 @@ load "../../helpers/ledger.bash" load "../../helpers/ln.bash" load "../../helpers/onchain.bash" load "../../helpers/subscriber.bash" +load "../../helpers/trigger.bash" load "../../helpers/user.bash" ALICE='alice' -TRIGGER_STOP_FILE="$BATS_ROOT_DIR/.stop_trigger" - setup_file() { create_user "$ALICE" add_callback "$ALICE" @@ -269,6 +268,7 @@ usd_amount=50 # Stop trigger touch $TRIGGER_STOP_FILE + retry 10 1 trigger_is_stopped || exit 1 # Generate invoice variables=$( @@ -286,7 +286,7 @@ usd_amount=50 # Start trigger rm $TRIGGER_STOP_FILE - sleep 5 + retry 10 1 trigger_is_started # Pay invoice & check for settled lnd_outside_cli payinvoice -f \ @@ -302,6 +302,7 @@ usd_amount=50 # Stop trigger touch $TRIGGER_STOP_FILE + retry 10 1 trigger_is_stopped || exit 1 # Generate invoice variables=$( @@ -319,7 +320,7 @@ usd_amount=50 # Start trigger rm $TRIGGER_STOP_FILE - sleep 5 + retry 10 1 trigger_is_started # Pay invoice & check for settled lnd_outside_cli payinvoice -f \ diff --git a/bats/helpers/trigger.bash b/bats/helpers/trigger.bash new file mode 100644 index 00000000000..d7be8bdd693 --- /dev/null +++ b/bats/helpers/trigger.bash @@ -0,0 +1,26 @@ +CURRENT_FILE=${BASH_SOURCE:-bats/helpers/.} +source "$(dirname "$CURRENT_FILE")/_common.bash" + +TRIGGER_STOP_FILE="$BATS_ROOT_DIR/.stop_trigger" + +trigger_is_stopped() { + local NUM_LINES=2 + cat $TILT_LOG_FILE | grep 'api-trigger │' \ + | tail -n $NUM_LINES \ + | grep "Successfully stopped trigger" + + return "$?" +} + +trigger_is_started() { + local NUM_LINES=18 + cat $TILT_LOG_FILE | grep 'api-trigger │' \ + | tail -n $NUM_LINES \ + | grep "Successfully stopped trigger" + + if [[ "$?" == "0" ]]; then + return 1 + else + return 0 + fi +}