itests.sh 2.7 KB

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