integration.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. kill_descendant_processes() {
  3. local pid="$1"
  4. local and_self="${2:-false}"
  5. if children="$(pgrep -P "$pid")"; then
  6. for child in $children; do
  7. kill_descendant_processes "$child" true
  8. done
  9. fi
  10. if [[ "$and_self" == true ]]; then
  11. kill -9 "$pid"
  12. fi
  13. }
  14. # Change directory to the first argument passed to the script
  15. cd "$1" || exit 1
  16. echo "Changed directory to $1"
  17. # Start the server in the background
  18. poetry run reflex run --env "$2" & pid=$!
  19. echo "Started server with PID $pid"
  20. # Wait for ports 3000 and 8000 to become available
  21. wait_time=0
  22. while ! nc -z localhost 3000 || ! lsof -i :8000 >/dev/null; do
  23. if ! kill -0 "$pid" >/dev/null 2>&1; then
  24. echo "Error: Server process with PID $pid exited early"
  25. break
  26. fi
  27. if ((wait_time >= 600)); then
  28. echo "Error: Timeout waiting for ports 3000 and 8000 to become available"
  29. exit 1
  30. fi
  31. sleep 5
  32. ((wait_time += 5))
  33. echo "Waiting for ports 3000 and 8000 to become available (waited $wait_time seconds)..."
  34. done
  35. # Check if the server is still running
  36. if kill -0 "$pid" >/dev/null 2>&1; then
  37. echo "Integration test passed"
  38. kill_descendant_processes $$
  39. exit 0
  40. else
  41. echo "Integration test failed"
  42. exit 1
  43. fi