itests.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. cargo build -p cdk-integration-tests
  36. cargo build --bin cdk-integration-tests
  37. cargo run --bin cdk-integration-tests &
  38. # Capture its PID
  39. CDK_ITEST_MINT_BIN_PID=$!
  40. TIMEOUT=100
  41. START_TIME=$(date +%s)
  42. # Loop until the endpoint returns a 200 OK status or timeout is reached
  43. while true; do
  44. # Get the current time
  45. CURRENT_TIME=$(date +%s)
  46. # Calculate the elapsed time
  47. ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
  48. # Check if the elapsed time exceeds the timeout
  49. if [ $ELAPSED_TIME -ge $TIMEOUT ]; then
  50. echo "Timeout of $TIMEOUT seconds reached. Exiting..."
  51. exit 1
  52. fi
  53. # Make a request to the endpoint and capture the HTTP status code
  54. HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" $URL)
  55. # Check if the HTTP status is 200 OK
  56. if [ "$HTTP_STATUS" -eq 200 ]; then
  57. echo "Received 200 OK from $URL"
  58. break
  59. else
  60. echo "Waiting for 200 OK response, current status: $HTTP_STATUS"
  61. sleep 2 # Wait for 2 seconds before retrying
  62. fi
  63. done
  64. # Run cargo test
  65. cargo test -p cdk-integration-tests
  66. # Capture the exit status of cargo test
  67. test_status=$?
  68. # Source PIDs from file
  69. source "$cdk_itests/pids.txt"
  70. # Exit with the status of the tests
  71. exit $test_status