Skip to content

Add artifact saving step to collect test results in dynamic method tests #9

Add artifact saving step to collect test results in dynamic method tests

Add artifact saving step to collect test results in dynamic method tests #9

name: Test Dynamic Docker Method
on:
push:
pull_request:
workflow_dispatch:
env:
DOCKER_BUILDKIT: 1
TEST_SCALE_COUNT: 3
jobs:
test-dynamic:
runs-on: ubuntu-latest
name: Dynamic Docker Method Tests
timeout-minutes: 30
outputs:
test_results: ${{ steps.collect-results.outputs.results }}
success_count: ${{ steps.collect-results.outputs.success_count }}
total_count: ${{ steps.collect-results.outputs.total_count }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Create empty wow-client directory
run: |
mkdir -p wow-client
echo "Created empty wow-client directory for testing"
- name: Make scripts executable
run: |
chmod +x manage-clients-dynamic.sh
chmod +x choose-approach.sh
- name: Test Dynamic - Setup
id: test-setup
run: |
echo "=== Testing Dynamic Method Setup ==="
if ./manage-clients-dynamic.sh setup; then
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=Setup completed successfully" >> $GITHUB_OUTPUT
else
echo "result=FAIL" >> $GITHUB_OUTPUT
echo "message=Setup failed" >> $GITHUB_OUTPUT
fi
- name: Test Dynamic - Build and Start Single Instance
id: test-single-start
run: |
echo "=== Testing Dynamic Method - Single Instance ==="
if timeout 300 ./manage-clients-dynamic.sh start 1; then
sleep 10
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=Single instance started successfully" >> $GITHUB_OUTPUT
else
echo "result=FAIL" >> $GITHUB_OUTPUT
echo "message=Failed to start single instance" >> $GITHUB_OUTPUT
fi
- name: Test Dynamic - Status Check
id: test-status
run: |
echo "=== Testing Dynamic Method - Status ==="
if ./manage-clients-dynamic.sh status; then
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=Status check completed" >> $GITHUB_OUTPUT
else
echo "result=FAIL" >> $GITHUB_OUTPUT
echo "message=Status check failed" >> $GITHUB_OUTPUT
fi
- name: Test Dynamic - Scale Up
id: test-scale-up
run: |
echo "=== Testing Dynamic Method - Scale Up to $TEST_SCALE_COUNT ==="
if timeout 300 ./manage-clients-dynamic.sh scale $TEST_SCALE_COUNT; then
echo "Waiting for containers to fully initialize..."
sleep 15
./manage-clients-dynamic.sh status
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=Scaled up to $TEST_SCALE_COUNT instances successfully" >> $GITHUB_OUTPUT
else
echo "result=FAIL" >> $GITHUB_OUTPUT
echo "message=Failed to scale up to $TEST_SCALE_COUNT instances" >> $GITHUB_OUTPUT
fi
- name: Test Multiple VNC Ports
id: test-multiple-vnc-ports
run: |
echo "=== Testing Multiple VNC Ports after scaling ==="
echo "Waiting for containers to start and VNC servers to initialize..."
# Function to check container logs for errors
check_container_logs() {
local container_name=$1
echo "--- Logs for $container_name ---"
docker logs --tail 20 "$container_name" 2>&1 || echo "No logs available for $container_name"
}
# Wait for VNC ports with retry logic (max 60 seconds)
vnc_ports_ok=0
max_wait=60
start_time=$(date +%s)
for i in $(seq 1 $TEST_SCALE_COUNT); do
port=$((5900 + i - 1))
container_name="wow-clients-client-$i"
echo "Checking VNC port $port for container $container_name..."
# Reset timer for each port
port_start_time=$(date +%s)
port_ready=false
while [ $(($(date +%s) - port_start_time)) -lt $max_wait ]; do
if netstat -tuln | grep -q ":$port "; then
echo "✅ VNC port $port is listening"
port_ready=true
vnc_ports_ok=$((vnc_ports_ok + 1))
break
else
echo "⏳ VNC port $port not ready yet, waiting..."
# Check if container is running
if ! docker ps -q --filter "name=^${container_name}$" | grep -q .; then
echo "❌ Container $container_name is not running!"
check_container_logs "$container_name"
break
fi
# Show container logs every 10 seconds for debugging
elapsed=$(($(date +%s) - port_start_time))
if [ $((elapsed % 10)) -eq 0 ] && [ $elapsed -gt 0 ]; then
echo "Container logs after ${elapsed}s:"
check_container_logs "$container_name"
fi
sleep 2
fi
done
if [ "$port_ready" = false ]; then
echo "❌ VNC port $port failed to become ready within $max_wait seconds"
check_container_logs "$container_name"
fi
done
# Final summary
echo "=== VNC Port Check Summary ==="
echo "Ready ports: $vnc_ports_ok/$TEST_SCALE_COUNT"
# Show all container statuses
echo "=== Container Status ==="
docker ps --filter "name=wow-clients-client-" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
if [ $vnc_ports_ok -eq $TEST_SCALE_COUNT ]; then
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=All $TEST_SCALE_COUNT VNC ports are listening correctly" >> $GITHUB_OUTPUT
elif [ $vnc_ports_ok -gt 0 ]; then
echo "result=PARTIAL" >> $GITHUB_OUTPUT
echo "message=$vnc_ports_ok/$TEST_SCALE_COUNT VNC ports are listening" >> $GITHUB_OUTPUT
else
echo "result=FAIL" >> $GITHUB_OUTPUT
echo "message=No VNC ports are listening after scaling" >> $GITHUB_OUTPUT
fi
- name: Test Dynamic - API Connectivity
id: test-api
run: |
echo "=== Testing Dynamic Method - API Tests ==="
echo "Waiting for API services to be ready..."
sleep 20
api_success=0
set -x # Enable debug mode to show commands being executed
# Debug container status
echo "DEBUG: Container status before health check:"
docker ps
# Test health endpoint with retry
echo "Testing health endpoint..."
for attempt in {1..10}; do
echo "DEBUG: Attempting health check $attempt"
health_status=$(curl -f -s -w "%{http_code}" http://localhost:5000/snapshot-info -o /dev/null || echo "failed")
echo "DEBUG: Health check status code: $health_status"
if [[ "$health_status" == "200" ]]; then
echo "✅ Health check passed on attempt $attempt"
echo "DEBUG: api_success before: $api_success"
api_success=$((api_success + 1))
echo "DEBUG: api_success after: $api_success"
break
else
echo "⏳ Health check attempt $attempt failed, retrying..."
if [ $attempt -eq 10 ]; then
echo "❌ Health check failed after 10 attempts"
echo "Container logs:"
docker logs --tail 20 wow-clients-client-1 2>&1 || echo "No logs available"
fi
sleep 3
fi
done
# Test desktop snapshot with retry
echo "Testing desktop snapshot..."
echo "DEBUG: Starting desktop snapshot test with set -e state: $-"
echo "DEBUG: Testing if we get here"
for attempt in {1..5}; do
echo "DEBUG: Attempting desktop snapshot $attempt"
snapshot_status=$(curl -f -s -w "%{http_code}" http://localhost:5000/desktop-snapshot -o /dev/null || echo "failed")
echo "DEBUG: Snapshot status code: $snapshot_status"
if [[ "$snapshot_status" == "200" ]]; then
echo "✅ Desktop snapshot passed on attempt $attempt"
echo "DEBUG: api_success before: $api_success"
api_success=$((api_success + 1))
echo "DEBUG: api_success after: $api_success"
break
else
echo "⏳ Desktop snapshot attempt $attempt failed, retrying..."
if [ $attempt -eq 5 ]; then
echo "❌ Desktop snapshot failed after 5 attempts"
echo "DEBUG: Container status after desktop snapshot failure:"
docker ps
echo "DEBUG: Checking container logs for API issues:"
docker logs --tail 20 wow-clients-client-1 2>&1 || echo "No logs available"
fi
sleep 5
fi
done
echo "DEBUG: Final api_success value: $api_success"
if [ $api_success -eq 2 ]; then
echo "DEBUG: All tests passed, setting output to PASS"
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=All API tests passed (2/2)" >> $GITHUB_OUTPUT
else
echo "DEBUG: Some tests failed, setting output to PARTIAL"
echo "result=PARTIAL" >> $GITHUB_OUTPUT
echo "message=API tests partially passed ($api_success/2)" >> $GITHUB_OUTPUT
fi
set +x # Disable debug mode
- name: Run API Test Script
id: test-api-script
run: |
echo "=== Running API Test Script ==="
python3 -m pip install requests pillow
if timeout 60 python3 test_api.py; then
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=API test script completed successfully" >> $GITHUB_OUTPUT
else
echo "result=PARTIAL" >> $GITHUB_OUTPUT
echo "message=API test script completed with some issues" >> $GITHUB_OUTPUT
fi
- name: Test VNC Port Listening
id: test-vnc-port
run: |
echo "=== Testing VNC Port Listening ==="
echo "Waiting for VNC port 5900 to be ready..."
# Wait for VNC port with retry logic (max 30 seconds)
max_wait=30
start_time=$(date +%s)
port_ready=false
while [ $(($(date +%s) - start_time)) -lt $max_wait ]; do
if netstat -tuln | grep -q ":5900 "; then
echo "✅ VNC port 5900 is listening"
port_ready=true
break
else
echo "⏳ VNC port 5900 not ready yet, waiting..."
# Check container logs for debugging
if docker ps -q --filter "name=wow-clients-client-1" | grep -q .; then
echo "Container logs:"
docker logs --tail 10 wow-clients-client-1 2>&1 || echo "No logs available"
fi
sleep 2
fi
done
if [ "$port_ready" = true ]; then
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=VNC port 5900 is listening" >> $GITHUB_OUTPUT
else
echo "result=FAIL" >> $GITHUB_OUTPUT
echo "message=VNC port 5900 is not listening after $max_wait seconds" >> $GITHUB_OUTPUT
fi
- name: Test VNC Connection Script
id: test-vnc-connection
run: |
echo "=== Testing VNC Connection ==="
if python3 test_vnc.py; then
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=VNC connection test passed" >> $GITHUB_OUTPUT
else
echo "result=FAIL" >> $GITHUB_OUTPUT
echo "message=VNC connection test failed" >> $GITHUB_OUTPUT
fi
- name: Test Dynamic - Scale Down
id: test-scale-down
run: |
echo "=== Testing Dynamic Method - Scale Down ==="
if ./manage-clients-dynamic.sh scale 1; then
sleep 5
./manage-clients-dynamic.sh status
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=Scaled down to 1 instance successfully" >> $GITHUB_OUTPUT
else
echo "result=FAIL" >> $GITHUB_OUTPUT
echo "message=Failed to scale down" >> $GITHUB_OUTPUT
fi
- name: Test Dynamic - Clean Stopped
id: test-clean-stopped
run: |
echo "=== Testing Dynamic Method - Clean Stopped ==="
if ./manage-clients-dynamic.sh clean-stopped; then
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=Clean stopped completed successfully" >> $GITHUB_OUTPUT
else
echo "result=FAIL" >> $GITHUB_OUTPUT
echo "message=Clean stopped failed" >> $GITHUB_OUTPUT
fi
- name: Test Dynamic - Stop All
id: test-stop
run: |
echo "=== Testing Dynamic Method - Stop All ==="
if ./manage-clients-dynamic.sh stop; then
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=Stop all completed successfully" >> $GITHUB_OUTPUT
else
echo "result=FAIL" >> $GITHUB_OUTPUT
echo "message=Stop all failed" >> $GITHUB_OUTPUT
fi
- name: Test Dynamic - Clean All
id: test-clean-all
run: |
echo "=== Testing Dynamic Method - Clean All ==="
if echo "y" | ./manage-clients-dynamic.sh clean-all; then
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=Clean all completed successfully" >> $GITHUB_OUTPUT
else
echo "result=PARTIAL" >> $GITHUB_OUTPUT
echo "message=Clean all completed with warnings" >> $GITHUB_OUTPUT
fi
- name: Verify Dynamic Cleanup
id: test-cleanup-verify
run: |
echo "=== Verifying Dynamic Method Cleanup ==="
containers=$(docker ps -a --filter "name=wow-clients-client-" --format "{{.Names}}" | wc -l)
volumes=$(docker volume ls --filter "name=wow-clients" --format "{{.Name}}" | wc -l)
if [ $containers -eq 0 ] && [ $volumes -eq 0 ]; then
echo "result=PASS" >> $GITHUB_OUTPUT
echo "message=Cleanup verification passed - no resources left" >> $GITHUB_OUTPUT
else
echo "result=FAIL" >> $GITHUB_OUTPUT
echo "message=Cleanup verification failed - $containers containers, $volumes volumes remaining" >> $GITHUB_OUTPUT
fi
- name: Collect Test Results
id: collect-results
run: |
# Create JSON results
cat << 'EOF' > test_results.json
{
"setup": {
"result": "${{ steps.test-setup.outputs.result }}",
"message": "${{ steps.test-setup.outputs.message }}"
},
"single_start": {
"result": "${{ steps.test-single-start.outputs.result }}",
"message": "${{ steps.test-single-start.outputs.message }}"
},
"status_check": {
"result": "${{ steps.test-status.outputs.result }}",
"message": "${{ steps.test-status.outputs.message }}"
},
"scale_up": {
"result": "${{ steps.test-scale-up.outputs.result }}",
"message": "${{ steps.test-scale-up.outputs.message }}"
},
"multiple_vnc_ports": {
"result": "${{ steps.test-multiple-vnc-ports.outputs.result }}",
"message": "${{ steps.test-multiple-vnc-ports.outputs.message }}"
},
"api_connectivity": {
"result": "${{ steps.test-api.outputs.result }}",
"message": "${{ steps.test-api.outputs.message }}"
},
"api_script": {
"result": "${{ steps.test-api-script.outputs.result }}",
"message": "${{ steps.test-api-script.outputs.message }}"
},
"vnc_port_listening": {
"result": "${{ steps.test-vnc-port.outputs.result }}",
"message": "${{ steps.test-vnc-port.outputs.message }}"
},
"vnc_connection": {
"result": "${{ steps.test-vnc-connection.outputs.result }}",
"message": "${{ steps.test-vnc-connection.outputs.message }}"
},
"scale_down": {
"result": "${{ steps.test-scale-down.outputs.result }}",
"message": "${{ steps.test-scale-down.outputs.message }}"
},
"clean_stopped": {
"result": "${{ steps.test-clean-stopped.outputs.result }}",
"message": "${{ steps.test-clean-stopped.outputs.message }}"
},
"stop_all": {
"result": "${{ steps.test-stop.outputs.result }}",
"message": "${{ steps.test-stop.outputs.message }}"
},
"clean_all": {
"result": "${{ steps.test-clean-all.outputs.result }}",
"message": "${{ steps.test-clean-all.outputs.message }}"
},
"cleanup_verify": {
"result": "${{ steps.test-cleanup-verify.outputs.result }}",
"message": "${{ steps.test-cleanup-verify.outputs.message }}"
}
}
EOF
# Count successes
success_count=$(cat test_results.json | grep -o '"result": "PASS"' | wc -l)
partial_count=$(cat test_results.json | grep -o '"result": "PARTIAL"' | wc -l)
total_count=14
echo "results=$(cat test_results.json | tr -d '\n')" >> $GITHUB_OUTPUT
echo "success_count=$success_count" >> $GITHUB_OUTPUT
echo "total_count=$total_count" >> $GITHUB_OUTPUT
echo "partial_count=$partial_count" >> $GITHUB_OUTPUT
echo "=== Dynamic Method Test Summary ==="
echo "✅ Passed: $success_count/$total_count"
echo "⚠️ Partial: $partial_count/$total_count"
echo "❌ Failed: $((total_count - success_count - partial_count))/$total_count"
- name: Print Markdown Test Report
run: |
echo '## 🧪 Dynamic Docker Method Test Report'
echo ''
jq -r '
to_entries[] |
"### " + (.key | gsub("_"; " ") | ascii_upcase) + "\n- **Result:** " + .value.result + "\n- " + .value.message + "\n"
' test_results.json
echo ''
echo "| Test | Result | Message |"
echo "|------|--------|---------|"
jq -r '
to_entries[] |
"| " + (.key | gsub("_"; " ") | ascii_upcase) + " | " + .value.result + " | " + .value.message + " |"
' test_results.json
echo ''
echo "**Summary:**"
echo "- ✅ Passed: ${{ steps.collect-results.outputs.success_count }}/${{ steps.collect-results.outputs.total_count }}"
echo "- ⚠️ Partial: $(jq '[.[] | select(.result=="PARTIAL")] | length' test_results.json)/${{ steps.collect-results.outputs.total_count }}"
echo "- ❌ Failed: $(( ${{ steps.collect-results.outputs.total_count }} - ${{ steps.collect-results.outputs.success_count }} - $(jq '[.[] | select(.result=="PARTIAL")] | length' test_results.json) ))/${{ steps.collect-results.outputs.total_count }}"
- name: Save artifacts
uses: actions/upload-artifact@v3
with:
name: test-results
path: test_results.json
retention-days: 7