2012-03-01 21:04:16 +01:00
|
|
|
#!/usr/bin/env python
|
2012-09-10 14:39:51 +02:00
|
|
|
"""End to end tests for the utility programs.
|
2012-03-01 21:04:16 +01:00
|
|
|
|
2012-09-10 14:39:51 +02:00
|
|
|
This test assumes the utilities inside src directory have already been
|
|
|
|
built.
|
2012-03-01 21:04:16 +01:00
|
|
|
|
|
|
|
At the moment top_buiddir is not in the environment, but top_builddir would be
|
|
|
|
more reliable than '..', so it's worth trying to pull it from the environment.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Jim Morrison <jim@twist.com>'
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
|
|
_PORT = 9893
|
|
|
|
|
|
|
|
|
2012-03-01 21:09:31 +01:00
|
|
|
def _run_server(port, args):
|
2012-03-01 21:04:16 +01:00
|
|
|
srcdir = os.environ.get('srcdir', '.')
|
|
|
|
testdata = '%s/testdata' % srcdir
|
|
|
|
top_builddir = os.environ.get('top_builddir', '..')
|
2012-09-10 14:39:51 +02:00
|
|
|
base_args = ['%s/src/spdyd' % top_builddir, '-d', testdata]
|
2012-03-01 21:09:31 +01:00
|
|
|
if args:
|
|
|
|
base_args.extend(args)
|
2012-03-01 21:41:24 +01:00
|
|
|
base_args.extend([str(port), '%s/privkey.pem' % testdata,
|
|
|
|
'%s/cacert.pem' % testdata])
|
2012-03-01 21:09:31 +01:00
|
|
|
return subprocess.Popen(base_args)
|
2012-03-01 21:04:16 +01:00
|
|
|
|
|
|
|
def _check_server_up(port):
|
|
|
|
# Check this check for now.
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
def _kill_server(server):
|
|
|
|
while server.returncode is None:
|
|
|
|
server.terminate()
|
|
|
|
time.sleep(1)
|
|
|
|
server.poll()
|
|
|
|
|
|
|
|
|
|
|
|
class EndToEndSpdyTests(unittest.TestCase):
|
2012-03-01 21:09:31 +01:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2012-03-01 21:41:24 +01:00
|
|
|
cls.setUpServer([])
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpServer(cls, args):
|
|
|
|
cls.server = _run_server(_PORT, args)
|
2012-03-01 21:09:31 +01:00
|
|
|
_check_server_up(_PORT)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
_kill_server(cls.server)
|
|
|
|
|
2012-03-01 21:04:16 +01:00
|
|
|
def setUp(self):
|
|
|
|
build_dir = os.environ.get('top_builddir', '..')
|
2012-09-10 14:39:51 +02:00
|
|
|
self.client = '%s/src/spdycat' % build_dir
|
2012-03-01 21:41:24 +01:00
|
|
|
self.stdout = 'No output'
|
|
|
|
|
|
|
|
def call(self, path, args):
|
|
|
|
full_args = [self.client,'http://localhost:%d%s' % (_PORT, path)] + args
|
|
|
|
p = subprocess.Popen(full_args, stdout=subprocess.PIPE,
|
|
|
|
stdin=subprocess.PIPE)
|
|
|
|
self.stdout, self.stderr = p.communicate()
|
|
|
|
return p.returncode
|
|
|
|
|
2012-03-01 21:04:16 +01:00
|
|
|
|
2012-03-01 21:41:24 +01:00
|
|
|
class EndToEndSpdy2Tests(EndToEndSpdyTests):
|
2012-03-01 21:04:16 +01:00
|
|
|
def testSimpleRequest(self):
|
2012-03-01 21:41:24 +01:00
|
|
|
self.assertEquals(0, self.call('/', []))
|
2012-03-01 21:04:16 +01:00
|
|
|
|
2012-03-01 21:41:24 +01:00
|
|
|
def testSimpleRequestSpdy3(self):
|
|
|
|
self.assertEquals(0, self.call('/', ['-v', '-3']))
|
|
|
|
self.assertIn('NPN selected the protocol: spdy/3', self.stdout)
|
2012-03-01 21:04:16 +01:00
|
|
|
|
2012-03-02 19:59:07 +01:00
|
|
|
def testFailedRequests(self):
|
|
|
|
self.assertEquals(
|
|
|
|
2, self.call('/', ['https://localhost:25/', 'http://localhost:79']))
|
|
|
|
|
|
|
|
def testOneFailedRequest(self):
|
|
|
|
self.assertEquals(1, subprocess.call([self.client, 'http://localhost:2/']))
|
|
|
|
|
2012-04-04 19:19:00 +02:00
|
|
|
def testOneTimedOutRequest(self):
|
|
|
|
self.assertEquals(1, self.call('/?spdyd_do_not_respond_to_req=yes',
|
|
|
|
['--timeout=2']))
|
2012-04-05 20:11:02 +02:00
|
|
|
self.assertEquals(0, self.call('/', ['--timeout=20']))
|
2012-04-04 19:19:00 +02:00
|
|
|
|
2012-03-01 21:09:31 +01:00
|
|
|
|
2012-03-01 21:41:24 +01:00
|
|
|
class EndToEndSpdy3Tests(EndToEndSpdyTests):
|
2012-03-01 21:09:31 +01:00
|
|
|
@classmethod
|
2012-03-01 21:41:24 +01:00
|
|
|
def setUpClass(cls):
|
|
|
|
cls.setUpServer(['-3'])
|
2012-03-01 21:04:16 +01:00
|
|
|
|
2012-03-01 21:09:31 +01:00
|
|
|
def testSimpleRequest(self):
|
2012-03-01 21:41:24 +01:00
|
|
|
self.assertEquals(0, self.call('/', ['-v']))
|
|
|
|
self.assertIn('NPN selected the protocol: spdy/3', self.stdout)
|
2012-03-01 21:04:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-03-01 21:09:31 +01:00
|
|
|
unittest.main()
|