integration.sh 943 B

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