Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: media/tools/constrained_network_server/cns_test.py

Issue 10824224: Add CNS function to clean up port matching requester IP address. (Closed) Base URL: http://git.chromium.org/chromium/src.git@cns_apache
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/tools/constrained_network_server/cns.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Tests for Constrained Network Server.""" 6 """Tests for Constrained Network Server."""
7 import os 7 import os
8 import signal 8 import signal
9 import subprocess 9 import subprocess
10 import tempfile 10 import tempfile
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 108
109 # Update fake time to see if ports expire. 109 # Update fake time to see if ports expire.
110 self._current_time += self._EXPIRY_TIME 110 self._current_time += self._EXPIRY_TIME
111 111
112 # Send second Get() which would normally cause ports to expire. Ensure that 112 # Send second Get() which would normally cause ports to expire. Ensure that
113 # the ports did not expire. 113 # the ports did not expire.
114 self.assertEquals(self._pa.Get('test2'), cns._DEFAULT_CNS_PORT_RANGE[0] + 1) 114 self.assertEquals(self._pa.Get('test2'), cns._DEFAULT_CNS_PORT_RANGE[0] + 1)
115 self.assertEquals(set(self._pa._ports.keys()), set([ 115 self.assertEquals(set(self._pa._ports.keys()), set([
116 cns._DEFAULT_CNS_PORT_RANGE[0], cns._DEFAULT_CNS_PORT_RANGE[0] + 1])) 116 cns._DEFAULT_CNS_PORT_RANGE[0], cns._DEFAULT_CNS_PORT_RANGE[0] + 1]))
117 117
118 def testPortAllocatorCleanMatchingIP(self):
119 # Setup PortAllocator w/o port expiration.
120 self._pa = cns.PortAllocator(cns._DEFAULT_CNS_PORT_RANGE, 0)
121
122 # Ensure Get() succeeds and returns the correct port.
123 self.assertEquals(self._pa.Get('ip1', t=1), cns._DEFAULT_CNS_PORT_RANGE[0])
124 self.assertEquals(self._pa.Get('ip1', t=2),
125 cns._DEFAULT_CNS_PORT_RANGE[0] + 1)
126 self.assertEquals(self._pa.Get('ip1', t=3),
127 cns._DEFAULT_CNS_PORT_RANGE[0] + 2)
128 self.assertEquals(self._pa.Get('ip2', t=1),
129 cns._DEFAULT_CNS_PORT_RANGE[0] + 3)
130
131 self._pa.Cleanup(all_ports=False, request_ip='ip1')
132
133 self.assertEquals(self._pa._ports.keys(),
134 [cns._DEFAULT_CNS_PORT_RANGE[0] + 3])
135 self.assertEquals(self._pa.Get('ip2'), cns._DEFAULT_CNS_PORT_RANGE[0])
136 self.assertEquals(self._pa.Get('ip1'), cns._DEFAULT_CNS_PORT_RANGE[0] + 1)
137
138 self._pa.Cleanup(all_ports=False, request_ip='ip2')
139 self.assertEquals(self._pa._ports.keys(),
140 [cns._DEFAULT_CNS_PORT_RANGE[0] + 1])
141
142 self._pa.Cleanup(all_ports=False, request_ip='abc')
143 self.assertEquals(self._pa._ports.keys(),
144 [cns._DEFAULT_CNS_PORT_RANGE[0] + 1])
145
146 self._pa.Cleanup(all_ports=False, request_ip='ip1')
147 self.assertEquals(self._pa._ports.keys(), [])
148
118 149
119 class ConstrainedNetworkServerTest(unittest.TestCase): 150 class ConstrainedNetworkServerTest(unittest.TestCase):
120 """End to end tests for ConstrainedNetworkServer system. 151 """End to end tests for ConstrainedNetworkServer system.
121 152
122 These tests require root access and run the cherrypy server along with 153 These tests require root access and run the cherrypy server along with
123 tc/iptables commands. 154 tc/iptables commands.
124 """ 155 """
125 156
126 # Amount of time to wait for the CNS to start up. 157 # Amount of time to wait for the CNS to start up.
127 _SERVER_START_SLEEP_SECS = 1 158 _SERVER_START_SLEEP_SECS = 1
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 256
226 class DummyOptionsWithServer(object): 257 class DummyOptionsWithServer(object):
227 www_root = 'media' 258 www_root = 'media'
228 port = 9000 259 port = 9000
229 cherrypy.url = lambda: 'http://127.0.0.1:9000/ServeConstrained' 260 cherrypy.url = lambda: 'http://127.0.0.1:9000/ServeConstrained'
230 local_server_port = 8080 261 local_server_port = 8080
231 262
232 263
233 if __name__ == '__main__': 264 if __name__ == '__main__':
234 unittest.main() 265 unittest.main()
OLDNEW
« no previous file with comments | « media/tools/constrained_network_server/cns.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698