Verified Commit bb1bb3d6 authored by Johannes Visintini's avatar Johannes Visintini
Browse files

add timing output

parent d4eff8cf
......@@ -33,9 +33,10 @@ Check requests given in [example-requests.json](examples/example-requests.json):
```bash
% python3 check-ohsome-api.py -a v1 -r examples/example-requests.json
Running requests
POST 400: https://api.ohsome.org/v1/elements/count
POST 400: https://api.ohsome.org/v1/elements/count (0.10s)
{'time': '2010-01-01/2016-08-01/P2Y2M2D', 'filter': 'highway=residential and type:way', 'note': 'bboxes missing on purpose'}
100%|████████████████████████████████████████████████████████████████| 3/3 [00:02<00:00, 1.19it/s]
--------------------------------------------------
100%|████████████████████████████████████████████████████████████████| 3/3 [00:01<00:00, 2.24it/s]
Result:
Status Amount
200 66.67 %
......@@ -49,9 +50,10 @@ Check requests given in [example-requests.json](examples/example-requests.json)
```bash
% python3 check-ohsome-api.py -b http://localhost:8080 -r examples/example-requests.json
Running requests
POST 400: http://localhost:8080/elements/count
POST 400: http://localhost:8082/elements/count (0.16s)
{'time': '2010-01-01/2016-08-01/P2Y2M2D', 'filter': 'highway=residential and type:way', 'note': 'bboxes missing on purpose'}
100%|████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 11.03it/s]
--------------------------------------------------
100%|████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 3.33it/s]
Result:
Status Amount
200 66.67 %
......
......@@ -2,6 +2,8 @@
import argparse
import json
from datetime import timedelta
import requests
from collections import Counter
......@@ -46,6 +48,7 @@ def perform_requests(test_requests, args):
status_codes = []
print("Running requests")
t = tqdm(test_requests)
elapsed_time = 0
for request in t:
t.set_description("{} {}".format(request['method'], request['url']))
if request['method'] == 'GET':
......@@ -54,7 +57,8 @@ def perform_requests(test_requests, args):
r = requests.post(request['url'], data=request['parameters'])
status_codes.append(r.status_code)
if r.status_code != 200 or args.debug or args.verbose:
tqdm.write('{} {}: {}'.format(request['method'], r.status_code, r.url))
duration = t.format_dict['elapsed'] - elapsed_time
tqdm.write('{} {}: {} ({:.2f}s)'.format(request['method'], r.status_code, r.url, duration))
if request['method'] == 'POST':
tqdm.write(' → {:.200}'.format(str(request['parameters'])))
if args.debug:
......@@ -62,6 +66,7 @@ def perform_requests(test_requests, args):
tqdm.write(r.text)
tqdm.write('-'*50)
t.set_description('')
elapsed_time = t.format_dict['elapsed']
return status_codes
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment