FloorManager / test_backend.sh
BolyosCsaba
initial commit
148a4a7
#!/bin/bash
echo "πŸ§ͺ Testing OFP Floor Manager Backend"
echo "======================================"
echo ""
# Start the server in background
echo "πŸ“‘ Starting Gradio server..."
python3 test_app.py > /tmp/gradio_test.log 2>&1 &
SERVER_PID=$!
# Wait for server to start
echo "⏳ Waiting for server to start..."
sleep 5
# Check if server is running
if ! ps -p $SERVER_PID > /dev/null; then
echo "❌ Server failed to start. Check logs:"
cat /tmp/gradio_test.log
exit 1
fi
echo "βœ… Server started (PID: $SERVER_PID)"
echo ""
# Test 1: Create Session
echo "πŸ§ͺ Test 1: Creating new session..."
RESPONSE=$(curl -s -X POST http://localhost:7860/api/predict \
-H "Content-Type: application/json" \
-d '{"fn_index": 0, "data": [], "session_hash": "test_session_1"}')
if echo "$RESPONSE" | grep -q "session_"; then
echo "βœ… Session created successfully"
SESSION_ID=$(echo "$RESPONSE" | grep -o 'session_[a-z0-9]*' | head -1)
echo " Session ID: $SESSION_ID"
else
echo "❌ Failed to create session"
echo " Response: $RESPONSE"
fi
echo ""
# Test 2: Add Agent
echo "πŸ§ͺ Test 2: Adding agent 'Alice'..."
RESPONSE=$(curl -s -X POST http://localhost:7860/api/predict \
-H "Content-Type: application/json" \
-d '{"fn_index": 1, "data": ["Alice"], "session_hash": "test_session_1"}')
if echo "$RESPONSE" | grep -q "Alice"; then
echo "βœ… Agent added successfully"
else
echo "❌ Failed to add agent"
fi
echo ""
# Test 3: Add Another Agent
echo "πŸ§ͺ Test 3: Adding agent 'Bob'..."
RESPONSE=$(curl -s -X POST http://localhost:7860/api/predict \
-H "Content-Type: application/json" \
-d '{"fn_index": 1, "data": ["Bob"], "session_hash": "test_session_1"}')
if echo "$RESPONSE" | grep -q "Bob"; then
echo "βœ… Agent added successfully"
else
echo "❌ Failed to add agent"
fi
echo ""
# Test 4: Send Message
echo "πŸ§ͺ Test 4: Sending message from Alice..."
RESPONSE=$(curl -s -X POST http://localhost:7860/api/predict \
-H "Content-Type: application/json" \
-d '{"fn_index": 2, "data": ["Alice", "Hello Bob!"], "session_hash": "test_session_1"}')
if echo "$RESPONSE" | grep -q "Hello Bob"; then
echo "βœ… Message sent successfully"
else
echo "❌ Failed to send message"
fi
echo ""
# Test 5: Grant Floor
echo "πŸ§ͺ Test 5: Granting floor to Bob..."
RESPONSE=$(curl -s -X POST http://localhost:7860/api/predict \
-H "Content-Type: application/json" \
-d '{"fn_index": 3, "data": ["Bob"], "session_hash": "test_session_1"}')
if echo "$RESPONSE" | grep -q "granted"; then
echo "βœ… Floor granted successfully"
else
echo "❌ Failed to grant floor"
fi
echo ""
echo "======================================"
echo "πŸŽ‰ All tests completed!"
echo ""
# Show server logs
echo "πŸ“‹ Server logs:"
tail -20 /tmp/gradio_test.log
echo ""
echo "πŸ›‘ Stopping server (PID: $SERVER_PID)..."
kill $SERVER_PID
wait $SERVER_PID 2>/dev/null
echo "βœ… Server stopped"
echo ""
echo "πŸ’‘ To run the server interactively: python3 test_app.py"