summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorshadi@chromium.org <shadi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-09 21:10:54 +0000
committershadi@chromium.org <shadi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-09 21:10:54 +0000
commite07f01be9bf10adf7047169e99d5b62049cb01dd (patch)
tree4349a72379bc94e490e269f4bfec9625a1e31ec5 /media
parent82c40477604845df63544e8a2ac4294ba80b82eb (diff)
downloadchromium_src-e07f01be9bf10adf7047169e99d5b62049cb01dd.zip
chromium_src-e07f01be9bf10adf7047169e99d5b62049cb01dd.tar.gz
chromium_src-e07f01be9bf10adf7047169e99d5b62049cb01dd.tar.bz2
Add support to disable CNS port expiration and improve error logging.
In an attempt at fixing http://crbug.com/110541, we added video event logging and minor changes. The bug seems related to audio problems, however seemed worthwhile to submit in any case since the behavior of an expiry_time <= 0 was not defined. BUG=110541 TEST=manual runs. Review URL: http://codereview.chromium.org/9290028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121295 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rwxr-xr-xmedia/tools/constrained_network_server/cns.py16
-rwxr-xr-xmedia/tools/constrained_network_server/cns_test.py18
2 files changed, 27 insertions, 7 deletions
diff --git a/media/tools/constrained_network_server/cns.py b/media/tools/constrained_network_server/cns.py
index 9f6c1a0..71ba9d7 100755
--- a/media/tools/constrained_network_server/cns.py
+++ b/media/tools/constrained_network_server/cns.py
@@ -92,7 +92,8 @@ class PortAllocator(object):
# Cleanup ports on new port requests. Do it after the cache check though
# so we don't erase and then setup the same port.
- self._CleanupLocked(all_ports=False)
+ if self._expiry_time_secs > 0:
+ self._CleanupLocked(all_ports=False)
# Performance isn't really an issue here, so just iterate over the port
# range to find an unused port. If no port is found, None is returned.
@@ -122,7 +123,7 @@ class PortAllocator(object):
traffic_control.CreateConstrainedPort(kwargs)
return True
except traffic_control.TrafficControlError as e:
- cherrypy.log('Error: %s\nOutput: %s', e.msg, e.error)
+ cherrypy.log('Error: %s\nOutput: %s' % (e.msg, e.error))
return False
def _CleanupLocked(self, all_ports):
@@ -151,7 +152,7 @@ class PortAllocator(object):
try:
traffic_control.DeleteConstrainedPort(self._ports[port]['config'])
except traffic_control.TrafficControlError as e:
- cherrypy.log('Error: %s\nOutput: %s', e.msg, e.error)
+ cherrypy.log('Error: %s\nOutput: %s' % (e.msg, e.error))
def Cleanup(self, interface, all_ports=False):
"""Cleans up expired ports, or if all_ports=True, all allocated ports.
@@ -275,7 +276,7 @@ def ParseArgs():
parser.add_option('--expiry-time', type='int',
default=_DEFAULT_PORT_EXPIRY_TIME_SECS,
help=('Number of seconds before constrained ports expire '
- 'and are cleaned up. Default: %default'))
+ 'and are cleaned up. 0=Disabled. Default: %default'))
parser.add_option('--port', type='int', default=_DEFAULT_SERVING_PORT,
help='Port to serve the API on. Default: %default')
parser.add_option('--port-range', default=_DEFAULT_CNS_PORT_RANGE,
@@ -291,8 +292,8 @@ def ParseArgs():
parser.add_option('--www-root', default=os.getcwd(),
help=('Directory root to serve files from. Defaults to the '
'current directory: %default'))
- parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
- default=False, help='Turn on verbose output.')
+ parser.add_option('-v', '--verbose', action='store_true', default=False,
+ help='Turn on verbose output.')
options = parser.parse_args()[0]
@@ -303,6 +304,9 @@ def ParseArgs():
except ValueError:
parser.error('Invalid port range specified.')
+ if options.expiry_time < 0:
+ parser.error('Invalid expiry time specified.')
+
# Convert the path to an absolute to remove any . or ..
options.www_root = os.path.abspath(options.www_root)
diff --git a/media/tools/constrained_network_server/cns_test.py b/media/tools/constrained_network_server/cns_test.py
index 319f33a..0a6e995 100755
--- a/media/tools/constrained_network_server/cns_test.py
+++ b/media/tools/constrained_network_server/cns_test.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -99,6 +99,22 @@ class PortAllocatorTest(unittest.TestCase):
self.assertEquals(set(self._pa._ports.keys()), set([
cns._DEFAULT_CNS_PORT_RANGE[0], cns._DEFAULT_CNS_PORT_RANGE[0] + 1]))
+ def testPortAllocatorNoExpiration(self):
+ # Setup PortAllocator w/o port expiration.
+ self._pa = cns.PortAllocator(cns._DEFAULT_CNS_PORT_RANGE, 0)
+
+ # Ensure Get() succeeds and returns the correct port.
+ self.assertEquals(self._pa.Get('test'), cns._DEFAULT_CNS_PORT_RANGE[0])
+
+ # Update fake time to see if ports expire.
+ self._current_time += self._EXPIRY_TIME
+
+ # Send second Get() which would normally cause ports to expire. Ensure that
+ # the ports did not expire.
+ self.assertEquals(self._pa.Get('test2'), cns._DEFAULT_CNS_PORT_RANGE[0] + 1)
+ self.assertEquals(set(self._pa._ports.keys()), set([
+ cns._DEFAULT_CNS_PORT_RANGE[0], cns._DEFAULT_CNS_PORT_RANGE[0] + 1]))
+
class ConstrainedNetworkServerTest(unittest.TestCase):
"""End to end tests for ConstrainedNetworkServer system."""