media/tools/constrained_network_server/cns_test.py
def testServerLatencyConstraint(self):
    """Tests serving a file with a latency network constraint."""
    # Abort if does not have root access.
    self.assertEqual(os.geteuid(), 0, 'You need root access to run this test.')
    now = time.time()

    base_url = '%sf=%s' % (self._SERVER_URL, self._relative_fn)
    url = '%s&latency=%d' % (base_url, self._LATENCY_TEST_SECS * 1000)
    f = urllib2.urlopen(url)

    # Verify file data is served correctly.
    self.assertEqual(self._TEST_DATA, f.read())

    # Verify the request took longer than the requested latency.
    self.assertTrue(time.time() - now > self._LATENCY_TEST_SECS)

    # Verify the server properly redirected the URL.
    self.assertTrue(f.geturl().startswith(base_url.replace(
        str(cns._DEFAULT_SERVING_PORT), str(cns._DEFAULT_CNS_PORT_RANGE[0]))))
Tests serving a file with a latency network constraint.
Tests serving a file with a latency network constraint.
Tests serving a file with a latency network constraint .
def testServerLatencyConstraint(self):
    self.assertEqual(os.geteuid(), 0, 'You need root access to run this test.')
    now = time.time()
    base_url = '%sf=%s' % (self._SERVER_URL, self._relative_fn)
    url = '%s&latency=%d' % (base_url, self._LATENCY_TEST_SECS * 1000)
    f = urllib2.urlopen(url)
    self.assertEqual(self._TEST_DATA, f.read())
    self.assertTrue(time.time() - now > self._LATENCY_TEST_SECS)
    self.assertTrue(f.geturl().startswith(base_url.replace(
        str(cns._DEFAULT_SERVING_PORT), str(cns._DEFAULT_CNS_PORT_RANGE[0]))))
def testServerLatencyConstraint ( self ) : self . assertEqual ( os . geteuid ( ) , 0 , 'You need root access to run this test.' ) now = time . time ( ) base_url = '%sf=%s' % ( self . _SERVER_URL , self . _relative_fn ) url = '%s&latency=%d' % ( base_url , self . _LATENCY_TEST_SECS * 1000 ) f = urllib2 . urlopen ( url ) self . assertEqual ( self . _TEST_DATA , f . read ( ) ) self . assertTrue ( time . time ( ) - now > self . _LATENCY_TEST_SECS ) self . assertTrue ( f . geturl ( ) . startswith ( base_url . replace ( str ( cns . _DEFAULT_SERVING_PORT ) , str ( cns . _DEFAULT_CNS_PORT_RANGE [ 0 ] ) ) ) )
Tests serving a file with a latency network constraint.
Tests serving a file with a latency network constraint .
"""Tests serving a file with a latency network constraint.""" # Abort if does not have root access. # Verify file data is served correctly. # Verify the request took longer than the requested latency. # Verify the server properly redirected the URL.
self