fake_itests.sh 2.2 KB

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