Update test.sh
This commit is contained in:
50
test.sh
50
test.sh
@@ -221,37 +221,38 @@ function start_test_server() {
|
|||||||
while [ $attempt -lt $max_attempts ]; do
|
while [ $attempt -lt $max_attempts ]; do
|
||||||
# Try multiple connection methods for different environments
|
# Try multiple connection methods for different environments
|
||||||
local http_code="000"
|
local http_code="000"
|
||||||
local test_urls=""
|
local container_code="000"
|
||||||
|
local host_code="000"
|
||||||
|
local local_code="000"
|
||||||
|
|
||||||
# Try direct container IP on port 80 (might work in some Docker setups)
|
# Try direct container IP on port 80 (might work in some Docker setups)
|
||||||
if [ "${CONTAINER_IP}" != "localhost" ]; then
|
if [ "${CONTAINER_IP}" != "localhost" ]; then
|
||||||
http_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://${CONTAINER_IP}:80/" 2>/dev/null || echo "000")
|
container_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://${CONTAINER_IP}:80/" 2>/dev/null || echo "000")
|
||||||
test_urls="${CONTAINER_IP}:80"
|
if [ "$container_code" != "000" ] && [ "$container_code" != "" ]; then
|
||||||
|
http_code="$container_code"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If that didn't work, try host IP with mapped port (Docker-in-Docker)
|
# Try host IP with mapped port (Docker-in-Docker)
|
||||||
if [ "$http_code" = "000" ] || [ "$http_code" = "" ]; then
|
|
||||||
if [ -n "${HOST_IP}" ]; then
|
if [ -n "${HOST_IP}" ]; then
|
||||||
local host_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://${HOST_IP}:${TEST_PORT}/" 2>/dev/null || echo "000")
|
host_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://${HOST_IP}:${TEST_PORT}/" 2>/dev/null || echo "000")
|
||||||
if [ "$host_code" != "000" ] && [ "$host_code" != "" ]; then
|
if [ "$host_code" != "000" ] && [ "$host_code" != "" ]; then
|
||||||
http_code="$host_code"
|
http_code="$host_code"
|
||||||
fi
|
fi
|
||||||
test_urls="${test_urls}, host:${HOST_IP}:${TEST_PORT}"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If that didn't work, try localhost with mapped port (local Docker)
|
# Try localhost with mapped port (local Docker)
|
||||||
if [ "$http_code" = "000" ] || [ "$http_code" = "" ]; then
|
local_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://localhost:${TEST_PORT}/" 2>/dev/null || echo "000")
|
||||||
local local_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://localhost:${TEST_PORT}/" 2>/dev/null || echo "000")
|
|
||||||
if [ "$local_code" != "000" ] && [ "$local_code" != "" ]; then
|
if [ "$local_code" != "000" ] && [ "$local_code" != "" ]; then
|
||||||
http_code="$local_code"
|
http_code="$local_code"
|
||||||
fi
|
fi
|
||||||
test_urls="${test_urls}, localhost:${TEST_PORT}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Debug: Show HTTP code and container status on first few attempts
|
# Debug: Show HTTP codes from all attempts on first few tries
|
||||||
if [ $attempt -lt 3 ]; then
|
if [ $attempt -lt 3 ]; then
|
||||||
log_info "Health check attempt $((attempt + 1)): HTTP code ${http_code} (tried: ${test_urls})"
|
log_info "Health check attempt $((attempt + 1)):"
|
||||||
|
log_info " Container IP (${CONTAINER_IP}:80): ${container_code}"
|
||||||
|
log_info " Host IP (${HOST_IP}:${TEST_PORT}): ${host_code}"
|
||||||
|
log_info " Localhost (localhost:${TEST_PORT}): ${local_code}"
|
||||||
# Check if container is actually running
|
# Check if container is actually running
|
||||||
if docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
if docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
||||||
log_info "Container is running, checking logs..."
|
log_info "Container is running, checking logs..."
|
||||||
@@ -261,19 +262,18 @@ function start_test_server() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$http_code" = "200" ] || [ "$http_code" = "204" ] || [ "$http_code" = "404" ]; then
|
# Check if any method succeeded
|
||||||
log_info "Server is ready! (HTTP ${http_code})"
|
if [ "$container_code" = "200" ] || [ "$container_code" = "204" ] || [ "$container_code" = "404" ]; then
|
||||||
# Determine which connection method worked
|
|
||||||
if curl -s --max-time 1 -o /dev/null "http://${CONTAINER_IP}:80/" 2>/dev/null; then
|
|
||||||
export SOS_TEST_HOST="${CONTAINER_IP}:80"
|
export SOS_TEST_HOST="${CONTAINER_IP}:80"
|
||||||
log_info "Using container IP: ${SOS_TEST_HOST}"
|
log_info "Server is ready! Using container IP: ${SOS_TEST_HOST}"
|
||||||
elif [ -n "${HOST_IP}" ] && curl -s --max-time 1 -o /dev/null "http://${HOST_IP}:${TEST_PORT}/" 2>/dev/null; then
|
return 0
|
||||||
|
elif [ "$host_code" = "200" ] || [ "$host_code" = "204" ] || [ "$host_code" = "404" ]; then
|
||||||
export SOS_TEST_HOST="${HOST_IP}:${TEST_PORT}"
|
export SOS_TEST_HOST="${HOST_IP}:${TEST_PORT}"
|
||||||
log_info "Using host IP: ${SOS_TEST_HOST}"
|
log_info "Server is ready! Using host IP: ${SOS_TEST_HOST}"
|
||||||
else
|
return 0
|
||||||
|
elif [ "$local_code" = "200" ] || [ "$local_code" = "204" ] || [ "$local_code" = "404" ]; then
|
||||||
export SOS_TEST_HOST="localhost:${TEST_PORT}"
|
export SOS_TEST_HOST="localhost:${TEST_PORT}"
|
||||||
log_info "Using localhost: ${SOS_TEST_HOST}"
|
log_info "Server is ready! Using localhost: ${SOS_TEST_HOST}"
|
||||||
fi
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user