|
| 1 | +cd app |
| 2 | + |
| 3 | +# We first run the command with different entry point which starts unblocking script |
| 4 | +# so we don't need to start it in background. It will install the dependencies as part of the command |
| 5 | +trace $CLI apps run-local --prepare-environment --entry-point test.yml 2>&1 | grep -w "Hello, world" |
| 6 | + |
| 7 | +# Get 3 unique ports sequentially to avoid conflicts |
| 8 | +PORTS=$(allocate_ports.py 3 | tr -d '\r') |
| 9 | + |
| 10 | +# Read ports into array |
| 11 | +PORTS_ARR=($(echo "$PORTS")) |
| 12 | +PORT="${PORTS_ARR[0]}" |
| 13 | +DEBUG_PORT="${PORTS_ARR[1]}" |
| 14 | +PROXY_PORT="${PORTS_ARR[2]}" |
| 15 | + |
| 16 | +title "Starting the app in background..." |
| 17 | +trace $CLI apps run-local --prepare-environment --debug --port "$PROXY_PORT" --debug-port "$DEBUG_PORT" --app-port "$PORT" > ../out.run.txt 2>&1 & |
| 18 | +PID=$! |
| 19 | +# Ensure background process is killed on script exit |
| 20 | +trap '(kill $PID >/dev/null 2>&1) 2>/dev/null || true' EXIT |
| 21 | +cd .. |
| 22 | + |
| 23 | +title Waiting for the app to start... |
| 24 | +# Use a loop to check for the startup message instead of tail/sed which can be unreliable on Windows |
| 25 | +# due to file locking, buffering issues, and different text processing behavior across Windows versions. |
| 26 | +# A simple grep loop is more robust across platforms. |
| 27 | +while [ -z "$(grep -o "Server is running on port " out.run.txt 2>/dev/null)" ]; do |
| 28 | + sleep 1 |
| 29 | +done |
| 30 | + |
| 31 | +title "Checking app is running..." |
| 32 | +trace curl -s -o - http://127.0.0.1:$PROXY_PORT | grep -w "Hello From App" |
| 33 | + |
| 34 | +title "Sending shutdown request..." |
| 35 | +trace curl -s -o /dev/null http://127.0.0.1:$PROXY_PORT/shutdown || true |
| 36 | + |
| 37 | +# We need to wait for the app to shutdown before we can exit the test meaning wait until the |
| 38 | +# server is closed. We need to poll because the server is closed asynchronously. |
| 39 | +while [ -z "$(grep -o "Server closed" out.run.txt 2>/dev/null)" ]; do |
| 40 | + sleep 1 |
| 41 | +done |
| 42 | + |
| 43 | +# Wait for the background process to actually terminate |
| 44 | +wait $PID 2>/dev/null || true |
| 45 | +echo "Process terminated" |
| 46 | + |
| 47 | +rm out.run.txt |
0 commit comments