Add test for --timeout.
authorEmil Mikulic <emikulic@gmail.com>
Mon, 10 Dec 2018 12:52:42 +0000 (23:52 +1100)
committerEmil Mikulic <emikulic@gmail.com>
Mon, 10 Dec 2018 12:52:42 +0000 (23:52 +1100)
TODO
devel/run-tests
devel/test_timeout.py [new file with mode: 0755]

diff --git a/TODO b/TODO
index 60edc1b..d94db58 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,4 +1,3 @@
 - keepalive performance against ab sucks
 - keepalive+TCP_NODELAY hangs!
 - send headers using sendfile syscall - fewer packets
-- add test for timeout
index a8b66a1..8742689 100755 (executable)
@@ -97,6 +97,15 @@ runtests() {
   kill $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
     echo "FAIL: stderr should have been empty."
     exit 1
diff --git a/devel/test_timeout.py b/devel/test_timeout.py
new file mode 100755 (executable)
index 0000000..ae32298
--- /dev/null
@@ -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: