Skip to content

Commit

Permalink
fix: add tests for python worker deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
majorgreys committed Dec 23, 2021
1 parent e24fef1 commit eafb025
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tests/deadlocks/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def application(env, start_response):
start_response("200 OK", [("Content-Type", "text/plain")])
message = "Hello World"
return [message.encode("utf-8")]
5 changes: 5 additions & 0 deletions tests/deadlocks/master-nothreads.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[uwsgi]
show-config = true
master = true
enable-threads = false
workers = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[uwsgi]
show-config = true
master = true
enable-threads = true
workers = 10
single-interpreter = true
6 changes: 6 additions & 0 deletions tests/deadlocks/master-singleinterpreter-threads-1worker.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[uwsgi]
show-config = true
master = true
enable-threads = true
workers = 1
single-interpreter = true
5 changes: 5 additions & 0 deletions tests/deadlocks/master-threads-10workers.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[uwsgi]
show-config = true
master = true
enable-threads = true
workers = 10
5 changes: 5 additions & 0 deletions tests/deadlocks/master-threads-1worker.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[uwsgi]
show-config = true
master = true
enable-threads = true
workers = 1
5 changes: 5 additions & 0 deletions tests/deadlocks/nomaster-threads-10workers.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[uwsgi]
show-config = true
master = false
enable-threads = true
workers = 10
5 changes: 5 additions & 0 deletions tests/deadlocks/nomaster-threads-1worker.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[uwsgi]
show-config = true
master = false
enable-threads = true
workers = 1
14 changes: 14 additions & 0 deletions tests/deadlocks/sitecustomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import threading
import time


def run():
print("[DEADLOCKS] started run")
st = time.time()
while time.time() < st + 5:
pass
print("[DEADLOCKS] finished run")

t = threading.Thread(target=run)
t.daemon = True
t.start()
21 changes: 19 additions & 2 deletions tests/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ test_python() {
}


test_python_deadlocks() {
date > reload.txt
rm -f uwsgi.log
echo -e "${bldyel}================== TESTING DEADLOCKS $1 $2 =====================${txtrst}"
echo -e "${bldyel}>>> Starting python app${txtrst}"
echo -en "${bldred}"
# initialize with tests/deadlocks/sitecustomize.py
PYTHONPATH=tests/deadlocks ./uwsgi --plugin 0:$1 --http :8080 --exit-on-reload --touch-reload reload.txt --wsgi-file tests/deadlocks/main.py --ini $2 --daemonize uwsgi.log
echo -en "${txtrst}"
http_test "http://localhost:8080/"
echo -e "${bldyel}===================== DONE $1 $2 =====================${txtrst}\n\n"
}


test_rack() {
date > reload.txt
rm -f uwsgi.log
Expand All @@ -90,8 +104,11 @@ while read PV ; do
test_python $PV $WSGI_FILE
done
done < <(cat "$CI_CONFIG" | grep "plugins/python base" | sed s_".*plugins/python base "_""_g)


while read PV ; do
for INI_FILE in tests/deadlocks/*.ini ; do
test_python_deadlocks $PV $INI_FILE
done
done < <(cat "$CI_CONFIG" | grep "plugins/python base" | sed s_".*plugins/python base "_""_g)
while read RV ; do
for RACK in examples/config2.ru ; do
test_rack $RV $RACK
Expand Down

0 comments on commit eafb025

Please sign in to comment.