[verification] Save timestamps of tests

Timestamps of tests should be helpful to map test execution with logs of
partial service. Should be helpful while debugging.

Change-Id: I543c653d76084e75f746756712acea400dadfcd0
This commit is contained in:
Andrey Kurilin 2017-01-16 16:26:00 +02:00
parent cbc6cddace
commit 6e6c59dba1
4 changed files with 20 additions and 10 deletions

View File

@ -177,6 +177,8 @@ class SubunitV2StreamResult(object):
if test_status == "inprogress":
# timestamp of test start
self._timestamps[test_id] = timestamp
self._tests[test_id]["timestamp"] = timestamp.strftime(
"%Y-%m-%dT%H:%M:%S%z")
elif test_status:
self._tests[test_id]["duration"] = "%.3f" % (
timestamp - self._timestamps[test_id]).total_seconds()

View File

@ -28,6 +28,9 @@ LP_BUG_LINK = "https://launchpad.net/bugs/%s"
class JSONReporter(reporter.VerificationReporter):
"""Generates verification report in JSON format."""
# ISO 8601
TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
@classmethod
def validate(cls, output_destination):
"""Validate destination of report.
@ -45,8 +48,8 @@ class JSONReporter(reporter.VerificationReporter):
for v in self.verifications:
verifications[v.uuid] = {
"started_at": v.created_at.strftime("%Y-%m-%d %H:%M:%S"),
"finished_at": v.updated_at.strftime("%Y-%m-%d %H:%M:%S"),
"started_at": v.created_at.strftime(self.TIME_FORMAT),
"finished_at": v.updated_at.strftime(self.TIME_FORMAT),
"status": v.status,
"run_args": v.run_args,
"tests_count": v.tests_count,
@ -102,6 +105,9 @@ class JSONReporter(reporter.VerificationReporter):
class HTMLReporter(JSONReporter):
"""Generates verification report in HTML format."""
# "T" separator of ISO 8601 is not user-friendly enough.
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
def generate(self):
report = self._generate()
uuids = report["verifications"].keys()

View File

@ -42,7 +42,8 @@ class SubunitParserTestCase(test.TestCase):
self.assertSequenceEqual([skipped_test], skipped_tests.keys())
self.assertEqual(
{"status": "skip", "reason": "This should be skipped.",
"duration": "0.000", "name": skipped_test, "tags": []},
"duration": "0.000", "name": skipped_test, "tags": [],
"timestamp": "2015-06-03T08:46:17+0000"},
skipped_tests[skipped_test])
failed_tests = result.filter_tests("fail")
@ -56,7 +57,8 @@ class SubunitParserTestCase(test.TestCase):
RuntimeError: broken setUp method
"""
self.assertEqual({"status": "fail", "traceback": trace, "tags": [],
"duration": "0.000", "name": failed_test},
"duration": "0.000", "name": failed_test,
"timestamp": "2015-06-03T08:46:22+0000"},
failed_tests[failed_test])
def test_filter_results(self):

View File

@ -148,8 +148,8 @@ class JSONReporterTestCase(test.TestCase):
self.assertEqual(
collections.OrderedDict(
[("foo-bar-1", {"status": "finished",
"started_at": "2001-01-01 00:00:00",
"finished_at": "2001-01-02 00:00:00",
"started_at": "2001-01-01T00:00:00",
"finished_at": "2001-01-02T00:00:00",
"tests_duration": 1.111,
"tests_count": 9,
"run_args": "set_name=compute",
@ -159,8 +159,8 @@ class JSONReporterTestCase(test.TestCase):
"expected_failures": 3,
"failures": 1}),
("foo-bar-2", {"status": "finished",
"started_at": "2002-01-01 00:00:00",
"finished_at": "2002-01-02 00:00:00",
"started_at": "2002-01-01T00:00:00",
"finished_at": "2002-01-02T00:00:00",
"tests_duration": 22.222,
"tests_count": 99,
"run_args": "set_name=full",
@ -170,8 +170,8 @@ class JSONReporterTestCase(test.TestCase):
"expected_failures": 33,
"failures": 11}),
("foo-bar-3", {"status": "finished",
"started_at": "2003-01-01 00:00:00",
"finished_at": "2003-01-02 00:00:00",
"started_at": "2003-01-01T00:00:00",
"finished_at": "2003-01-02T00:00:00",
"tests_duration": 33.333,
"tests_count": 99,
"run_args": "set_name=full",