Add test for --timeout.

This commit is contained in:
Emil Mikulic 2018-12-10 23:52:42 +11:00
parent f0a8dc6c6c
commit ba63a6d60f
3 changed files with 31 additions and 1 deletions

1
TODO
View File

@ -1,4 +1,3 @@
- keepalive performance against ab sucks - keepalive performance against ab sucks
- keepalive+TCP_NODELAY hangs! - keepalive+TCP_NODELAY hangs!
- send headers using sendfile syscall - fewer packets - send headers using sendfile syscall - fewer packets
- add test for timeout

View File

@ -97,6 +97,15 @@ runtests() {
kill $PID kill $PID
wait $PID wait $PID
echo "===> run --timeout tests"
./a.out $DIR --port $PORT --timeout 1 \
>>test.out.stdout 2>>test.out.stderr &
PID=$!
kill -0 $PID || exit 1
python test_timeout.py
kill $PID
wait $PID
if [[ -s test.out.stderr ]]; then if [[ -s test.out.stderr ]]; then
echo "FAIL: stderr should have been empty." echo "FAIL: stderr should have been empty."
exit 1 exit 1

22
devel/test_timeout.py Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
# This is run by the "run-tests" script.
import unittest
import signal
import socket
class TestTimeout(unittest.TestCase):
def test_timeout(self):
port = 12346
s = socket.socket()
s.connect(("0.0.0.0", port))
# Assumes the server has --timeout 1
signal.alarm(3)
# Expect to get EOF before the alarm fires.
ret = s.recv(1024)
signal.alarm(0)
self.assertEquals(ret, '')
if __name__ == '__main__':
unittest.main()
# vim:set ts=4 sw=4 et: