Skip to content

Commit

Permalink
add: siege_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ak0327 committed Mar 9, 2024
1 parent 2c7ec51 commit d924bb3
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 27 deletions.
7 changes: 4 additions & 3 deletions test/integration/integration_test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ http {
location /cgi-bin/ { root html;
index index_cgi.html;
limit_except GET POST { deny all; }
cgi_mode on;
cgi_extension py php sh;
cgi_timeout 5s; } # location
cgi_mode on;
cgi_extension py php sh;
cgi_timeout 1s; } # timeout: for test

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html { root html; } # location
Expand Down
58 changes: 36 additions & 22 deletions test/integration/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,86 @@ SUCCESS=0

get_test="./test/integration/test_get.sh"
$get_test
get_test_result=$?
get_res=$?


post_test="./test/integration/test_post.sh"
$post_test
post_test_result=$?
post_res=$?


delete_test="./test/integration/test_delete.sh"
$delete_test
delete_test_result=$?
delete_res=$?


cgi_test="./test/integration/test_cgi.sh"
$cgi_test
cgi_test_result=$?
cgi_res=$?


err_test="./test/integration/test_err.sh"
$err_test
err_test_result=$?
err_res=$?


siege_test="./test/integration/test_siege.sh"
$siege_test
siege_res=$?



if [ $get_test_result -eq $SUCCESS ]; then
echo -en "[${GREEN}OK${RESET}] "

if [ $get_res -eq $SUCCESS ]; then
echo -en " [${GREEN}OK${RESET}] "
else
echo -en "[${RED}NG${RESET}] "
echo -en " [${RED}NG${RESET}] "
fi
echo "$get_test"


if [ $post_test_result -eq $SUCCESS ]; then
echo -en "[${GREEN}OK${RESET}] "
if [ $post_res -eq $SUCCESS ]; then
echo -en " [${GREEN}OK${RESET}] "
else
echo -en "[${RED}NG${RESET}] "
echo -en " [${RED}NG${RESET}] "
fi
echo "$post_test"


if [ $delete_test_result -eq $SUCCESS ]; then
echo -en "[${GREEN}OK${RESET}] "
if [ $delete_res -eq $SUCCESS ]; then
echo -en " [${GREEN}OK${RESET}] "
else
echo -en "[${RED}NG${RESET}] "
echo -en " [${RED}NG${RESET}] "
fi
echo "$delete_test"


if [ $cgi_test_result -eq $SUCCESS ]; then
echo -en "[${GREEN}OK${RESET}] "
if [ $cgi_res -eq $SUCCESS ]; then
echo -en " [${GREEN}OK${RESET}] "
else
echo -en "[${RED}NG${RESET}] "
echo -en " [${RED}NG${RESET}] "
fi
echo "$cgi_test"


if [ $err_test_result -eq $SUCCESS ]; then
echo -en "[${GREEN}OK${RESET}] "
if [ $err_res -eq $SUCCESS ]; then
echo -en " [${GREEN}OK${RESET}] "
else
echo -en "[${RED}NG${RESET}] "
echo -en " [${RED}NG${RESET}] "
fi
echo "$err_test"


total_result=$((get_test_result + post_test_result + delete_test_result + cgi_test_result + err_test_result))
if [ $total_result -ne 0 ]; then
if [ $siege_res -eq $SUCCESS ]; then
echo -en " [${GREEN}OK${RESET}] "
else
echo -en " [${RED}NG${RESET}] "
fi
echo "$siege_test"


total_res=$((get_res + post_res + delete_res + cgi_res + err_res + siege_res))
if [ $total_res -ne 0 ]; then
exit 1
fi

Expand Down
4 changes: 2 additions & 2 deletions test/integration/test_get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ echo " Failed Tests : $ng_cnt"
if [ $ng_cnt -gt 0 ]; then
for case in "${ng_cases[@]}"; do
echo -n " "
echo -e "${RED}$case${RESET}"
echo -e "${RED}${case}${RESET}"
done
fi

Expand All @@ -278,7 +278,7 @@ echo " Skipped Tests : $skip_cnt"
if [ $skip_cnt -gt 0 ]; then
for case in "${skip_cases[@]}"; do
echo -n " "
echo -e "${YELLOW}$case${RESET}"
echo -e "${YELLOW}${case}${RESET}"
done
fi

Expand Down
178 changes: 178 additions & 0 deletions test/integration/test_siege.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#!/bin/bash

source test/integration/test_func.sh
source test/integration/prepare_test_file.sh

################################################################################

CONF_PATH="test/integration/integration_test.conf"

RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
RESET="\033[0m"

SUCCESS=0
FAILURE=1

TRUE=1
FALSE=0

test_cnt=0

ng_cnt=0
ng_cases=()

defunct_generated=$FALSE
process_abort=$FALSE


siege_test() {
local concurrent=$1
local time=$2
local path=$3

local call_line=${BASH_LINENO[0]}

((test_cnt++))
echo -e "\nTEST No.${test_cnt} (L${call_line})"

defunct_before=0
defunct_after=0
defunct_count=0
fd_before=0
fd_after=0
test_ng=0

pkill webserv

defunct_before=$(ps aux | grep defunct | grep -v grep | wc -l)

./webserv $CONF_PATH 2>/dev/null &

fd_before=$(lsof -p $(pgrep webserv) | wc -l)

# echo "defunct_before:$defunct_before"
# echo "fd_before :$fd_before"

siege --benchmark --concurrent="$concurrent" --time="$time" "$path" > /dev/null 2>&1

sleep 3

defunct_after=$(ps aux | grep defunct | grep -v grep | wc -l)
defunct_count=$((defunct_after - defunct_before))
if [ $defunct_count -eq 0 ]; then
defunct_generated=$FALSE
else
defunct_generated=$TRUE
fi

fd_after=$(lsof -p $(pgrep webserv) | wc -l)

process_count=$(ps aux | grep '[w]ebserv' | wc -l)
if [ $process_count -eq 0 ]; then
process_abort=$TRUE
else
process_abort=$FALSE
pkill webserv
fi

# echo "defunct_after:$defunct_after"
# echo "fd_after :$fd_after"


if [ $defunct_generated -eq $FALSE ]; then
echo -e " [${GREEN}OK${RESET}] Defunct Process"
else
echo -e " [${RED}NG${RESET}] Defunct Process: $defunct_count defunct process generated"
test_ng=1
fi


if [ $fd_before -eq $fd_after ]; then
echo -e " [${GREEN}OK${RESET}] Fd"
else
echo -e " [${RED}NG${RESET}] Fd: $fd_before -> $fd_after"
test_ng=1
fi


if [ $process_abort -eq $FALSE ]; then
echo -e " [${GREEN}OK${RESET}] Process Running"
else
echo -e " [${RED}NG${RESET}] Process Aborted"
test_ng=1
fi

if [ $test_ng -ne 0 ]; then
((ng_cnt++))
ng_cases+=("No.${test_cnt} (L${call_line}): NG")
fi
}


################################################################################
echo "================================================================"
echo " SIEGE TEST"
echo "================================================================"

################################################################################


siege_test 8 5s "http://localhost:4343/"
siege_test 8 5s "http://localhost:4343/"
siege_test 8 5s "http://localhost:4343/nothing.html"
siege_test 8 3s "http://localhost:4343/cgi-bin/hello.py"
siege_test 8 3s "http://localhost:4343/cgi-bin/wrong_path.py"


siege_test 128 30s "http://localhost:4343/cgi-bin/hello.py"
siege_test 128 30s "http://localhost:4343/cgi-bin/nothing.html"
siege_test 128 30s "http://localhost:4343/cgi-bin/infinite_loop.py"
siege_test 128 30s "http://localhost:4343/cgi-bin/infinite_print.py"
siege_test 128 30s "http://localhost:4343/cgi-bin/out_of_range.py"
siege_test 128 30s "http://localhost:4343/cgi-bin/error_no_shebang.py"
siege_test 128 30s "http://localhost:4343/cgi-bin/sleep?60"
siege_test 128 30s "http://localhost:4343/cgi-bin/wrong_path.py"


siege_test 255 60s "http://localhost:4343/cgi-bin/hello.py"
siege_test 255 60s "http://localhost:4343/cgi-bin/nothing.html"
siege_test 255 60s "http://localhost:4343/cgi-bin/infinite_loop.py"
siege_test 255 60s "http://localhost:4343/cgi-bin/infinite_print.py"
siege_test 255 60s "http://localhost:4343/cgi-bin/out_of_range.py"
siege_test 255 60s "http://localhost:4343/cgi-bin/error_no_shebang.py"
siege_test 255 60s "http://localhost:4343/cgi-bin/sleep?60"
siege_test 255 60s "http://localhost:4343/cgi-bin/wrong_path.py"


################################################################################

echo
echo "================================================================"
echo " *** SIEGE RESULT ***"
exit_status=$FAILURE

exit_status=$FAILURE

if [ $ng_cnt -eq 0 ]; then
echo -e " ${GREEN}All tests passed successfully${RESET}"
exit_status=$SUCCESS
fi

echo " Total Tests : $test_cnt"

echo " Failed Tests : $ng_cnt"
if [ $ng_cnt -gt 0 ]; then
for case in "${ng_cases[@]}"; do
echo -n " "
echo -e "${RED}${case}${RESET}"
done
fi


echo -e "================================================================\n"

exit $exit_status

################################################################################

0 comments on commit d924bb3

Please sign in to comment.