itests.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env bash
  2. # Function to perform cleanup
  3. cleanup() {
  4. echo "Cleaning up..."
  5. # Kill the Rust binary process
  6. echo "Killing the Rust binary with PID $RUST_BIN_PID"
  7. kill $CDK_ITEST_MINT_BIN_PID
  8. # Wait for the Rust binary to terminate
  9. wait $CDK_ITEST_MINT_BIN_PID
  10. echo "Mint binary terminated"
  11. # Kill processes
  12. lncli --lnddir="$cdk_itests/lnd" --network=regtest stop
  13. lightning-cli --regtest --lightning-dir="$cdk_itests/cln/" stop
  14. bitcoin-cli --datadir="$cdk_itests/bitcoin" -rpcuser=testuser -rpcpassword=testpass -rpcport=18443 stop
  15. # Remove the temporary directory
  16. rm -rf "$cdk_itests"
  17. echo "Temp directory removed: $cdk_itests"
  18. unset cdk_itests
  19. unset cdk_itests_mint_addr
  20. unset cdk_itests_mint_port
  21. }
  22. # Set up trap to call cleanup on script exit
  23. trap cleanup EXIT
  24. # Create a temporary directory
  25. export cdk_itests=$(mktemp -d)
  26. export cdk_itests_mint_addr="127.0.0.1";
  27. export cdk_itests_mint_port=8085;
  28. URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port/v1/info"
  29. # Check if the temporary directory was created successfully
  30. if [[ ! -d "$cdk_itests" ]]; then
  31. echo "Failed to create temp directory"
  32. exit 1
  33. fi
  34. echo "Temp directory created: $cdk_itests"
  35. export MINT_DATABASE="$1";
  36. cargo build -p cdk-integration-tests
  37. cargo build --bin cdk-integration-tests
  38. cargo run --bin cdk-integration-tests &
  39. # Capture its PID
  40. CDK_ITEST_MINT_BIN_PID=$!
  41. TIMEOUT=100
  42. START_TIME=$(date +%s)
  43. # Loop until the endpoint returns a 200 OK status or timeout is reached
  44. while true; do
  45. # Get the current time
  46. CURRENT_TIME=$(date +%s)
  47. # Calculate the elapsed time
  48. ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
  49. # Check if the elapsed time exceeds the timeout
  50. if [ $ELAPSED_TIME -ge $TIMEOUT ]; then
  51. echo "Timeout of $TIMEOUT seconds reached. Exiting..."
  52. exit 1
  53. fi
  54. # Make a request to the endpoint and capture the HTTP status code
  55. HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" $URL)
  56. # Check if the HTTP status is 200 OK
  57. if [ "$HTTP_STATUS" -eq 200 ]; then
  58. echo "Received 200 OK from $URL"
  59. break
  60. else
  61. echo "Waiting for 200 OK response, current status: $HTTP_STATUS"
  62. sleep 2 # Wait for 2 seconds before retrying
  63. fi
  64. done
  65. # Run cargo test
  66. cargo test -p cdk-integration-tests --test regtest
  67. # Capture the exit status of cargo test
  68. test_status=$?
  69. # Exit with the status of the tests
  70. exit $test_status