Fix get_duration db api method
This commit fixes the db api method for getting the duration for a test_run. Originally this was just lazily copy and pasted from subunit-trace into the db_api without much thought. However now that there is a desire to use it, the method is refactored to actually work. Change-Id: Ib88a4774b1f0b23f57709aef9b7d34c457a4efdb
This commit is contained in:
parent
d5602539a6
commit
0a2fb7b7ac
@ -18,6 +18,7 @@ from oslo.db.sqlalchemy import utils as db_utils
|
|||||||
|
|
||||||
from subunit2sql.db import models
|
from subunit2sql.db import models
|
||||||
from subunit2sql import exceptions
|
from subunit2sql import exceptions
|
||||||
|
from subunit2sql import read_subunit
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
@ -232,16 +233,7 @@ def get_test_runs_by_run_id(run_id, session=None):
|
|||||||
return test_runs
|
return test_runs
|
||||||
|
|
||||||
|
|
||||||
def get_test_run_duration(test_run_id):
|
def get_test_run_duration(test_run_id, session=None):
|
||||||
session = get_session()
|
session = session or get_session()
|
||||||
|
|
||||||
test_run = get_test_run_by_id(test_run_id, session)
|
test_run = get_test_run_by_id(test_run_id, session)
|
||||||
start = test_run.start_time
|
return read_subunit.get_duration(test_run.start_time, test_run.stop_time)
|
||||||
end = test_run.end_time
|
|
||||||
if not start or not end:
|
|
||||||
duration = ''
|
|
||||||
else:
|
|
||||||
delta = end - start
|
|
||||||
duration = '%d.%06ds' % (
|
|
||||||
delta.days * DAY_SECONDS + delta.seconds, delta.microseconds)
|
|
||||||
return duration
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user