helpers.bash 487 B

12345678910111213141516171819202122
  1. ## add the retry function to bats
  2. # Retry a command $1 times until it succeeds. Wait $2 seconds between retries.
  3. function retry {
  4. local attempts=$1
  5. shift
  6. local delay=$1
  7. shift
  8. local i
  9. for ((i=0; i < attempts; i++)); do
  10. run "$@"
  11. if [ "$status" -eq 0 ]; then
  12. echo "$output"
  13. return 0
  14. fi
  15. sleep $delay
  16. done
  17. echo "Command \"$@\" failed $attempts times. Status: $status. Output: $output" >&2
  18. false
  19. }