Skip to content
Snippets Groups Projects
Commit 5ae42a15 authored by Eric Gribkoff's avatar Eric Gribkoff
Browse files

stop http2 test server with error code when failures occur

parent 5438888d
Branches
Tags
No related merge requests found
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
import argparse import argparse
import logging import logging
import sys
import twisted import twisted
import twisted.internet import twisted.internet
import twisted.internet.endpoints import twisted.internet.endpoints
...@@ -55,7 +56,7 @@ _TEST_CASE_MAPPING = { ...@@ -55,7 +56,7 @@ _TEST_CASE_MAPPING = {
class H2Factory(twisted.internet.protocol.Factory): class H2Factory(twisted.internet.protocol.Factory):
def __init__(self, testcase): def __init__(self, testcase):
logging.info('Creating H2Factory for new connection.') logging.info('Creating H2Factory for new connection (%s)', testcase)
self._num_streams = 0 self._num_streams = 0
self._testcase = testcase self._testcase = testcase
...@@ -83,6 +84,19 @@ def parse_arguments(): ...@@ -83,6 +84,19 @@ def parse_arguments():
) )
return parser.parse_args() return parser.parse_args()
exit_code = 0
def listen(endpoint, test_case):
deferred = endpoint.listen(H2Factory(test_case))
def listen_error(reason):
# If listening fails, we stop the reactor and exit the program
# with exit_code = 1.
global exit_code
exit_code = 1
logging.error('Listening failed: %s' % reason.value)
twisted.internet.reactor.stop()
deferred.addErrback(listen_error)
def start_test_servers(base_port): def start_test_servers(base_port):
""" Start one server per test case on incrementing port numbers """ Start one server per test case on incrementing port numbers
beginning with base_port """ beginning with base_port """
...@@ -92,7 +106,9 @@ def start_test_servers(base_port): ...@@ -92,7 +106,9 @@ def start_test_servers(base_port):
logging.warning('serving on port %d : %s'%(portnum, test_case)) logging.warning('serving on port %d : %s'%(portnum, test_case))
endpoint = twisted.internet.endpoints.TCP4ServerEndpoint( endpoint = twisted.internet.endpoints.TCP4ServerEndpoint(
twisted.internet.reactor, portnum, backlog=128) twisted.internet.reactor, portnum, backlog=128)
endpoint.listen(H2Factory(test_case)) # Wait until the reactor is running before calling endpoint.listen().
twisted.internet.reactor.callWhenRunning(listen, endpoint, test_case)
index += 1 index += 1
if __name__ == '__main__': if __name__ == '__main__':
...@@ -102,3 +118,4 @@ if __name__ == '__main__': ...@@ -102,3 +118,4 @@ if __name__ == '__main__':
args = parse_arguments() args = parse_arguments()
start_test_servers(args.base_port) start_test_servers(args.base_port)
twisted.internet.reactor.run() twisted.internet.reactor.run()
sys.exit(exit_code)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment