commit 1f4535bfefbf6a8cd6f7b9f26b1d76e8f7bec55c Author: David Fifield david@bamsoftware.com Date: Fri Apr 6 11:42:42 2012 -0700
Add a test for connector connection limits. --- connector-test.py | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/connector-test.py b/connector-test.py index 36c9208..d1a6bda 100755 --- a/connector-test.py +++ b/connector-test.py @@ -1,9 +1,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*-
+import socket +import subprocess import unittest from connector import WebSocketDecoder, WebSocketEncoder
+LOCAL_ADDRESS = ("127.0.0.1", 40000) +REMOTE_ADDRESS = ("127.0.0.1", 40001) + def read_frames(dec): frames = [] while True: @@ -176,5 +181,22 @@ class TestWebSocketEncoder(unittest.TestCase): dec.feed(enc_message) self.assertEqual(read_messages(dec), [(opcode, payload)])
+def format_address(addr): + return "%s:%d" % addr + +class TestConnectionLimit(unittest.TestCase): + def setUp(self): + self.p = subprocess.Popen(["./connector.py", format_address(LOCAL_ADDRESS), format_address(REMOTE_ADDRESS)]) + + def tearDown(self): + self.p.terminate() + + def test_remote_limit(self): + """Test that the connector limits the number of remote connections that + it will accept.""" + for i in range(5): + s = socket.create_connection(REMOTE_ADDRESS, 2) + self.assertRaises(socket.error, socket.create_connection, REMOTE_ADDRESS) + if __name__ == "__main__": unittest.main()
tor-commits@lists.torproject.org