commit b9e9ed718794e485b7bf3079d9e4d5c30e4d6c14 Author: David Fifield david@bamsoftware.com Date: Sat Jul 7 02:14:07 2012 -0700
Add skeleton facilitator test. --- Makefile | 1 + facilitator-test | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile index a12a9f3..3a15e54 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ clean: rm -rf dist
test: + ./facilitator-test ./flashproxy-client-test ./flashproxy-test.js
diff --git a/facilitator-test b/facilitator-test new file mode 100755 index 0000000..bdc064d --- /dev/null +++ b/facilitator-test @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import socket +import subprocess +import time +import unittest + +FACILITATOR_HOST = "127.0.0.1" +FACILITATOR_PORT = 9002 + +def gimme_socket(host, port): + addrinfo = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM, socket.IPPROTO_TCP)[0] + s = socket.socket(addrinfo[0], addrinfo[1], addrinfo[2]) + s.settimeout(10.0) + s.connect(addrinfo[4]) + return s + +class FacilitatorTest(unittest.TestCase): + def gimme_socket(self): + return gimme_socket(FACILITATOR_HOST, FACILITATOR_PORT) + + def setUp(self): + self.process = subprocess.Popen(["./facilitator", "-d", "-p", str(FACILITATOR_PORT), "-r", "0.0.0.0:0", "-l", "/dev/null"]) + time.sleep(0.1) + + def tearDown(self): + self.process.terminate() + + def test_timeout(self): + """Test that the socket will not accept slow writes indefinitely. + Successive sends should not reset the timeout counter.""" + s = self.gimme_socket() + time.sleep(0.3) + s.send("w") + time.sleep(0.3) + s.send("w") + time.sleep(0.3) + s.send("w") + time.sleep(0.3) + s.send("w") + time.sleep(0.3) + self.assertRaises(socket.error, s.send, "w") + +if __name__ == "__main__": + unittest.main()
tor-commits@lists.torproject.org