From aaaae5a6029d9d9b6a6fb215c37cd841e9a22863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 12 Nov 2012 15:57:56 +0100 Subject: [PATCH 1/2] * travis config with plugins for multiple python and ruby versions * basic script with tests for each python and rack plugin --- .travis.yml | 46 +++++++++++++++++++- tests/travis.sh | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 2 deletions(-) create mode 100755 tests/travis.sh diff --git a/.travis.yml b/.travis.yml index ab1f1e8e..2f34dac4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,47 @@ language: c + compiler: - - clang - gcc -script: python uwsgiconfig.py --build + - clang + +script: + - echo -e "\n\n>>> Building uWSGI binary" + - /usr/bin/python uwsgiconfig.py --build base + - echo -e "\n\n>>> Building python25 plugin" + - /usr/bin/python2.5 -V + - /usr/bin/python2.5 uwsgiconfig.py --plugin plugins/python base python25 + - echo -e "\n\n>>> Building python26 plugin" + - /usr/bin/python2.6 -V + - /usr/bin/python2.6 uwsgiconfig.py --plugin plugins/python base python26 + - echo -e "\n\n>>> Building python27 plugin" + - /usr/bin/python2.7 -V + - /usr/bin/python2.7 uwsgiconfig.py --plugin plugins/python base python27 + - echo -e "\n\n>>> Building python31 plugin" + - /usr/bin/python3.1 -V + - /usr/bin/python3.1 uwsgiconfig.py --plugin plugins/python base python31 + - echo -e "\n\n>>> Building python32 plugin" + - /usr/bin/python3.2 -V + - /usr/bin/python3.2 uwsgiconfig.py --plugin plugins/python base python32 + - echo -e "\n\n>>> Building python33 plugin" + - /usr/bin/python3.3 -V + - /usr/bin/python3.3 uwsgiconfig.py --plugin plugins/python base python33 + - echo -e "\n\n>>> Building rack 1.8.7 plugin" + - /usr/bin/ruby1.8 -v + - UWSGICONFIG_RUBYPATH=/usr/bin/ruby1.8 /usr/bin/python uwsgiconfig.py --plugin plugins/rack base rack187 + - echo -e "\n\n>>> Building rack 1.9.1 plugin" + - /usr/bin/ruby1.9.1 -v + - UWSGICONFIG_RUBYPATH=/usr/bin/ruby1.9.1 /usr/bin/python uwsgiconfig.py --plugin plugins/rack base rack191 + - echo -e "\n\n>>> Building cgi plugin" + - /usr/bin/python uwsgiconfig.py --plugin plugins/cgi base + - echo -e "\n\n>>> Building dummy plugin" + - /usr/bin/python uwsgiconfig.py --plugin plugins/dummy base + - echo -e "\n\n>>> Building done, starting tests" + - ./tests/travis.sh + +before_install: + - sudo add-apt-repository -y ppa:fkrull/deadsnakes + - sudo apt-get update -qq + - sudo apt-get install -qqyf python2.5-dev python2.6-dev python2.7-dev python3.1-dev python3.2-dev python3.3-dev rubygems1.8 ruby1.8-dev ruby1.9.1-dev + - sudo apt-get install -qqyf libxml2-dev libpcre3-dev libcap2-dev + - sudo apt-get install -qqyf curl + diff --git a/tests/travis.sh b/tests/travis.sh new file mode 100755 index 00000000..5e386ff7 --- /dev/null +++ b/tests/travis.sh @@ -0,0 +1,113 @@ +#!/bin/bash + + +txtund=$(tput sgr 0 1) # underline +txtbld=$(tput bold) # bold +bldred=${txtbld}$(tput setaf 1) # red +bldgre=${txtbld}$(tput setaf 2) # green +bldyel=${txtbld}$(tput setaf 3) # yellow +bldblu=${txtbld}$(tput setaf 4) # blue +txtcya=$(tput setaf 6) # cyan +bldwht=${txtbld}$(tput setaf 7) # white +txtrst=$(tput sgr0) # reset + + +ERROR=0 +SUCCESS=0 + + +die() { + date > reload.txt + sleep 3 + pidof uwsgi && killall uwsgi + sleep 1 + pidof uwsgi && killall -9 uwsgi + echo -e "$@" + if [ -e uwsgi.log ]; then + echo -e "${bldyel}>>> uwsgi.log:${txtrst}" + echo -e "${txtcya}" + cat uwsgi.log + echo -e "${txtrst}" + fi +} + + +http_test() { + URL=$1 + UPID=`pidof uwsgi` + if [ "$UPID" != "" ]; then + echo -e "${bldgre}>>> Spawned PID $UPID, running tests${txtrst}" + sleep 5 + curl -I $URL + RET=$? + if [ $RET != 0 ]; then + die "${bldred}>>> Error during curl run${txtrst}" + ERROR=$((ERROR+1)) + else + SUCCESS=$((SUCCESS+1)) + fi + die "${bldyel}>>> SUCCESS: Done${txtrst}" + else + die "${bldred}>>> ERROR: uWSGI did not start${txtrst}" + ERROR=$((ERROR+1)) + fi +} + + +test_python() { + date > reload.txt + rm -f uwsgi.log + echo -e "${bldyel}================== TESTING $1 =====================${txtrst}" + echo -e "${bldyel}>>> Spawning uWSGI python app${txtrst}" + echo -en "${bldred}" + ./uwsgi --master --plugin 0:$1 --http :8080 --exit-on-reload --touch-reload reload.txt --wsgi-file tests/staticfile.py --daemonize uwsgi.log + echo -en "${txtrst}" + http_test "http://localhost:8080/" + echo -e "${bldyel}===================== DONE $1 =====================${txtrst}\n\n" +} + + +test_rack() { + date > reload.txt + rm -f uwsgi.log + echo -e "${bldyel}================== TESTING $1 =====================${txtrst}" + case "$1" in + "rack187") + GEMS_BINARY="/usr/bin/gem1.8" + ;; + "rack191") + GEMS_BINARY="/usr/bin/gem1.9.1" + ;; + "rack193") + GEMS_BINARY="/usr/bin/gem1.9.3" + ;; + esac + echo -e "${bldyel}>>> Installing sinatra gem using ${GEMS_BINARY}${txtrst}" + $GEMS_BINARY install sinatra || die + echo -e "${bldyel}>>> Spawning uWSGI rack app${txtrst}" + echo -en "${bldred}" + ./uwsgi --master --plugin 0:$1 --http :8080 --exit-on-reload --touch-reload reload.txt --rack config2.ru --daemonize uwsgi.log + echo -en "${txtrst}" + http_test "http://localhost:8080/hi" + echo -e "${bldyel}===================== DONE $1 =====================${txtrst}\n\n" +} + + +while read PV ; do + test_python $PV +done < <(cat .travis.yml | grep "plugins/python base" | awk '{print $7}') + + +while read RV ; do + test_rack $RV +done < <(cat .travis.yml | grep "plugins/rack base" | awk '{print $8}') + + +echo "${bldgre}>>> $SUCCESS SUCCESSFUL PLUGIN(S)${txtrst}" +if [ $ERROR -ge 1 ]; then + echo "${bldred}>>> $ERROR FAILED PLUGIN(S)${txtrst}" + exit 1 +fi + +exit 0 + From e23a7bfd807029e99b138116341973db6f0a7feb Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Thu, 15 Nov 2012 14:18:45 +0200 Subject: [PATCH 2/2] support asynchronous requests in Lua plugin --- plugins/lua/lua_plugin.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/lua/lua_plugin.c b/plugins/lua/lua_plugin.c index 2cd27bb5..ea69cc6e 100644 --- a/plugins/lua/lua_plugin.c +++ b/plugins/lua/lua_plugin.c @@ -308,6 +308,8 @@ static const luaL_reg uwsgi_api[] = { static int uwsgi_lua_input(lua_State *L) { struct wsgi_request *wsgi_req = current_wsgi_req(); + int fd = wsgi_req->async_post ? + fileno(wsgi_req->async_post) : wsgi_req->poll.fd; ssize_t sum, len, total; char *buf, *ptr; @@ -330,7 +332,7 @@ static int uwsgi_lua_input(lua_State *L) { ptr = buf; while(total) { - len = read(wsgi_req->poll.fd, ptr, total); + len = read(fd, ptr, total); ptr += len; total -= len; }