Skip to content

Commit ad40220

Browse files
committed
refactor autobahn test runners
* client & server: keep running on exception during case run * client: display case ID's
1 parent 03b7e67 commit ad40220

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

autobahn/client.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
test_client.py in wsproto.
44
'''
55
import argparse
6+
import json
67
import logging
8+
import sys
79

810
import trio
911
from trio_websocket import open_websocket_url, ConnectionClosed
@@ -23,6 +25,12 @@ async def get_case_count(url):
2325
return int(case_count)
2426

2527

28+
async def get_case_info(url, case):
29+
url = f'{url}/getCaseInfo?case={case}'
30+
async with open_websocket_url(url) as conn:
31+
return json.loads(await conn.get_message())
32+
33+
2634
async def run_case(url, case):
2735
url = f'{url}/runCase?case={case}&agent={AGENT}'
2836
try:
@@ -52,13 +60,23 @@ async def run_tests(args):
5260
logging.getLogger('trio-websocket').setLevel(logging.DEBUG)
5361
else:
5462
case_count = await get_case_count(args.url)
55-
test_cases = range(1, case_count + 1)
63+
test_cases = list(range(1, case_count + 1))
64+
exception_cases = []
5665
for case in test_cases:
66+
case_id = (await get_case_info(args.url, case))['id']
5767
if case_count:
58-
logger.info("Running test case %d of %d", case, case_count)
68+
logger.info("Running test case %s (%d of %d)", case_id, case, case_count)
5969
else:
60-
logger.info("Debugging test case %d", case)
61-
await run_case(args.url, case)
70+
logger.info("Debugging test case %s (%d)", case_id, case)
71+
try:
72+
await run_case(args.url, case)
73+
except Exception: # pylint: disable=broad-exception-caught
74+
logger.exception(' runtime exception during test case %s (%d)', case_id, case)
75+
exception_cases.append(case_id)
76+
if exception_cases:
77+
logger.error('Runtime exception in %d of %d test cases: %s',
78+
len(exception_cases), len(test_cases), exception_cases)
79+
sys.exit(1)
6280
if not args.debug_cases:
6381
# Don't update report when debugging a single test case. It adds noise
6482
# to the debug logging.
@@ -71,6 +89,7 @@ def parse_args():
7189
parser = argparse.ArgumentParser(description='Autobahn client for'
7290
' trio-websocket')
7391
parser.add_argument('url', help='WebSocket URL for server')
92+
# TODO: accept case ID's rather than indices
7493
parser.add_argument('debug_cases', type=int, nargs='*', help='Run'
7594
' individual test cases with debug logging (optional)')
7695
return parser.parse_args()

autobahn/server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
import logging
1313

1414
import trio
15-
from trio_websocket import serve_websocket, ConnectionClosed
16-
15+
from trio_websocket import serve_websocket, ConnectionClosed, WebSocketRequest
1716

1817
BIND_IP = '0.0.0.0'
1918
BIND_PORT = 9000
@@ -31,7 +30,7 @@ async def main():
3130
max_message_size=MAX_MESSAGE_SIZE)
3231

3332

34-
async def handler(request):
33+
async def handler(request: WebSocketRequest):
3534
''' Reverse incoming websocket messages and send them back. '''
3635
global connection_count # pylint: disable=global-statement
3736
connection_count += 1
@@ -43,6 +42,8 @@ async def handler(request):
4342
await ws.send_message(message)
4443
except ConnectionClosed:
4544
break
45+
except Exception: # pylint: disable=broad-exception-caught
46+
logger.exception(' runtime exception handling connection #%d', connection_count)
4647

4748

4849
def parse_args():

docs/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ In the second terminal, you will run the Docker image::
151151
-p 9000:9000 \
152152
--name autobahn \
153153
crossbario/autobahn-testsuite \
154-
/usr/local/bin/wstest --mode fuzzingclient --spec /config/fuzzingclient.json
154+
wstest --mode fuzzingclient --spec /config/fuzzingclient.json
155155

156156
If a test fails, ``server.py`` does not support the same ``debug_cases``
157157
argument as ``client.py``, but you can modify `fuzzingclient.json` to specify a

0 commit comments

Comments
 (0)