aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/http2_test
diff options
context:
space:
mode:
authorGravatar Eric Gribkoff <ericgribkoff@google.com>2017-03-10 12:04:49 -0800
committerGravatar Eric Gribkoff <ericgribkoff@google.com>2017-03-17 00:46:01 -0700
commit5ae42a15cfe0c99711da4865541eb6e6e45dbd48 (patch)
tree35d9f7ccbed2b04d8ee69c18d7ed670d54d42716 /test/http2_test
parent5438888d3c6505c94dd3223c1dece087ee5829cc (diff)
stop http2 test server with error code when failures occur
Diffstat (limited to 'test/http2_test')
-rw-r--r--test/http2_test/http2_test_server.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/test/http2_test/http2_test_server.py b/test/http2_test/http2_test_server.py
index abde3433ad..81ee1df9f6 100644
--- a/test/http2_test/http2_test_server.py
+++ b/test/http2_test/http2_test_server.py
@@ -31,6 +31,7 @@
import argparse
import logging
+import sys
import twisted
import twisted.internet
import twisted.internet.endpoints
@@ -55,7 +56,7 @@ _TEST_CASE_MAPPING = {
class H2Factory(twisted.internet.protocol.Factory):
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._testcase = testcase
@@ -83,6 +84,19 @@ def parse_arguments():
)
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):
""" Start one server per test case on incrementing port numbers
beginning with base_port """
@@ -92,7 +106,9 @@ def start_test_servers(base_port):
logging.warning('serving on port %d : %s'%(portnum, test_case))
endpoint = twisted.internet.endpoints.TCP4ServerEndpoint(
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
if __name__ == '__main__':
@@ -102,3 +118,4 @@ if __name__ == '__main__':
args = parse_arguments()
start_test_servers(args.base_port)
twisted.internet.reactor.run()
+ sys.exit(exit_code)