|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set -e |
|
|
|
|
|
|
|
|
GREEN='\033[0;32m' |
|
|
RED='\033[0;31m' |
|
|
YELLOW='\033[1;33m' |
|
|
BLUE='\033[0;34m' |
|
|
NC='\033[0m' |
|
|
|
|
|
|
|
|
IMAGE_NAME="openspiel-env:latest" |
|
|
CONTAINER_NAME="openspiel-test" |
|
|
PORT=8000 |
|
|
HEALTH_CHECK_URL="http://localhost:${PORT}/health" |
|
|
MAX_WAIT=30 |
|
|
|
|
|
|
|
|
GAMES=("catch" "tic_tac_toe" "kuhn_poker" "cliff_walking" "2048" "blackjack") |
|
|
|
|
|
|
|
|
declare -a RESULTS |
|
|
PASSED=0 |
|
|
FAILED=0 |
|
|
|
|
|
echo -e "${BLUE}========================================${NC}" |
|
|
echo -e "${BLUE}OpenSpiel Docker Integration Test${NC}" |
|
|
echo -e "${BLUE}========================================${NC}" |
|
|
echo "" |
|
|
|
|
|
|
|
|
cleanup() { |
|
|
echo -e "${YELLOW}Cleaning up containers...${NC}" |
|
|
docker stop ${CONTAINER_NAME} 2>/dev/null || true |
|
|
docker rm ${CONTAINER_NAME} 2>/dev/null || true |
|
|
} |
|
|
|
|
|
|
|
|
wait_for_health() { |
|
|
local game=$1 |
|
|
echo -e " โณ Waiting for server to be ready..." |
|
|
|
|
|
for i in $(seq 1 $MAX_WAIT); do |
|
|
if curl -s -f ${HEALTH_CHECK_URL} > /dev/null 2>&1; then |
|
|
echo -e " ${GREEN}โ${NC} Server ready (${i}s)" |
|
|
return 0 |
|
|
fi |
|
|
sleep 1 |
|
|
done |
|
|
|
|
|
echo -e " ${RED}โ${NC} Server health check failed after ${MAX_WAIT}s" |
|
|
return 1 |
|
|
} |
|
|
|
|
|
|
|
|
test_game() { |
|
|
local game=$1 |
|
|
echo -e "\n${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}" |
|
|
echo -e "${BLUE}Testing: ${game}${NC}" |
|
|
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}" |
|
|
|
|
|
|
|
|
cleanup |
|
|
|
|
|
|
|
|
echo -e " ๐ณ Starting Docker container..." |
|
|
docker run -d \ |
|
|
--name ${CONTAINER_NAME} \ |
|
|
-p ${PORT}:8000 \ |
|
|
-e OPENSPIEL_GAME=${game} \ |
|
|
${IMAGE_NAME} > /dev/null |
|
|
|
|
|
|
|
|
if ! wait_for_health ${game}; then |
|
|
echo -e " ${RED}โ FAILED${NC} - Server did not start" |
|
|
RESULTS+=("${game}:FAILED:Server did not start") |
|
|
FAILED=$((FAILED + 1)) |
|
|
cleanup |
|
|
return 1 |
|
|
fi |
|
|
|
|
|
|
|
|
echo -e " ๐ฎ Running Python client test..." |
|
|
if NO_PROXY=localhost,127.0.0.1 HTTP_PROXY= HTTPS_PROXY= \ |
|
|
PYTHONPATH=$PWD/src:$PYTHONPATH \ |
|
|
python3 examples/openspiel_simple.py > /tmp/test_${game}.log 2>&1; then |
|
|
|
|
|
|
|
|
if grep -q "Episode finished!" /tmp/test_${game}.log; then |
|
|
echo -e " ${GREEN}โ PASSED${NC} - Episode completed successfully" |
|
|
RESULTS+=("${game}:PASSED") |
|
|
PASSED=$((PASSED + 1)) |
|
|
else |
|
|
echo -e " ${RED}โ FAILED${NC} - Episode did not complete" |
|
|
RESULTS+=("${game}:FAILED:Episode incomplete") |
|
|
FAILED=$((FAILED + 1)) |
|
|
fi |
|
|
else |
|
|
echo -e " ${RED}โ FAILED${NC} - Python client error" |
|
|
RESULTS+=("${game}:FAILED:Client error") |
|
|
FAILED=$((FAILED + 1)) |
|
|
fi |
|
|
|
|
|
|
|
|
cleanup |
|
|
} |
|
|
|
|
|
|
|
|
for game in "${GAMES[@]}"; do |
|
|
test_game ${game} |
|
|
done |
|
|
|
|
|
|
|
|
echo -e "\n${BLUE}========================================${NC}" |
|
|
echo -e "${BLUE}Test Summary${NC}" |
|
|
echo -e "${BLUE}========================================${NC}" |
|
|
echo "" |
|
|
|
|
|
for result in "${RESULTS[@]}"; do |
|
|
IFS=':' read -r game status message <<< "$result" |
|
|
if [ "$status" == "PASSED" ]; then |
|
|
echo -e " ${GREEN}โ${NC} ${game}" |
|
|
else |
|
|
echo -e " ${RED}โ${NC} ${game} - ${message}" |
|
|
fi |
|
|
done |
|
|
|
|
|
echo "" |
|
|
echo -e "Total: ${PASSED} passed, ${FAILED} failed out of ${#GAMES[@]} games" |
|
|
echo "" |
|
|
|
|
|
|
|
|
if [ $FAILED -eq 0 ]; then |
|
|
echo -e "${GREEN}========================================${NC}" |
|
|
echo -e "${GREEN}All tests PASSED! ๐${NC}" |
|
|
echo -e "${GREEN}========================================${NC}" |
|
|
exit 0 |
|
|
else |
|
|
echo -e "${RED}========================================${NC}" |
|
|
echo -e "${RED}Some tests FAILED${NC}" |
|
|
echo -e "${RED}========================================${NC}" |
|
|
exit 1 |
|
|
fi |
|
|
|