bugfix: uniform response time unit to miliseconds

This commit is contained in:
debugtalk
2018-03-27 18:36:23 +08:00
parent 45207bbf73
commit ede7d66eaa
3 changed files with 7 additions and 7 deletions

View File

@@ -103,8 +103,8 @@ class HttpSession(requests.Session):
self.meta_data["request_time"] = time.time()
response = self._send_request_safe_mode(method, url, **kwargs)
# record the consumed time
self.meta_data["response_time"] = int((time.time() - self.meta_data["request_time"]) * 1000)
self.meta_data["elapsed"] = response.elapsed.total_seconds()
self.meta_data["response_time(ms)"] = round((time.time() - self.meta_data["request_time"]) * 1000, 2)
self.meta_data["elapsed(ms)"] = response.elapsed.microseconds / 1000.0
self.meta_data["url"] = (response.history and response.history[0] or response)\
.request.path_url
@@ -138,9 +138,9 @@ class HttpSession(requests.Session):
logger.log_error(u"{exception}".format(exception=str(e)))
else:
logger.log_info(
"""status_code: {}, response_time: {} ms, response_length: {} bytes""".format(
"""status_code: {}, response_time(ms): {} ms, response_length: {} bytes""".format(
self.meta_data["status_code"],
self.meta_data["response_time"],
self.meta_data["response_time(ms)"],
self.meta_data["content_size"]
)
)

View File

@@ -71,7 +71,7 @@ def make_json_serializable(raw_json):
keyorder = ["url", "method", "request_headers", "request_body", "request_time",
"status_code", "response_headers", "response_body",
"content_size", "response_time", "elapsed"]
"content_size", "response_time(ms)", "elapsed(ms)"]
serializable_ordered_json = OrderedDict(
sorted(serializable_json.items(), key=lambda x:keyorder.index(x[0])))
@@ -97,7 +97,7 @@ class HtmlTestResult(unittest.TextTestResult):
self.records.append({
'name': test.shortDescription(),
'status': status,
'response_time': test.meta_data.get("response_time", 0),
'response_time_ms': test.meta_data.get("response_time(ms)", 0),
'attachment': attachment,
"meta_data": make_json_serializable(test.meta_data)
})

View File

@@ -180,7 +180,7 @@
<tr>
<th class="{{record.status}}" style="width:5em;">{{record.status}}</td>
<td>{{record.name}}</td>
<td style="text-align:center;width:6em;">{{ '%0.1f'| format(record.response_time|float) }} ms</td>
<td style="text-align:center;width:6em;">{{ '%0.1f'| format(record.response_time_ms|float) }} ms</td>
<td class="detail">
<a class="button" href="#popup_log_{{loop.index}}">log</a>