Add total run time to the runs table
This commit adds calculating the total run time in secs and storing that in the runs table to the script. This also converts the column in the runs table to be a float not an int. Normally this would require a separate migration but since I just pushed this I'm assuming I'm not going to break existing DBs.
This commit is contained in:
parent
082715bb28
commit
fe76e50b61
@ -65,7 +65,7 @@ class Run(BASE, SubunitBase):
|
||||
skips = sa.Column(sa.Integer())
|
||||
fails = sa.Column(sa.Integer())
|
||||
passes = sa.Column(sa.Integer())
|
||||
run_time = sa.Column(sa.Integer())
|
||||
run_time = sa.Column(sa.Float())
|
||||
artifacts = sa.Column(sa.Text())
|
||||
|
||||
|
||||
|
@ -35,7 +35,7 @@ def upgrade():
|
||||
sa.Column('skips', sa.Integer()),
|
||||
sa.Column('fails', sa.Integer()),
|
||||
sa.Column('passes', sa.Integer()),
|
||||
sa.Column('run_time', sa.Integer()),
|
||||
sa.Column('run_time', sa.Float()),
|
||||
sa.Column('artifacts', sa.Text()),
|
||||
mysql_engine=True)
|
||||
|
||||
|
@ -17,6 +17,8 @@ import functools
|
||||
import subunit
|
||||
import testtools
|
||||
|
||||
DAY_SECONDS = 60 * 60 * 24
|
||||
|
||||
|
||||
class ReadSubunit(object):
|
||||
|
||||
@ -36,6 +38,7 @@ class ReadSubunit(object):
|
||||
self.stream.run(self.result)
|
||||
finally:
|
||||
self.result.stopTestRun()
|
||||
self.results['run_time'] = self.run_time()
|
||||
return self.results
|
||||
|
||||
def parse_outcome(self, test):
|
||||
@ -80,3 +83,19 @@ class ReadSubunit(object):
|
||||
newname += name[tags_end + 1:]
|
||||
name = newname
|
||||
return name
|
||||
|
||||
def get_duration(self, start, end):
|
||||
if not start or not end:
|
||||
duration = ''
|
||||
else:
|
||||
delta = end - start
|
||||
duration = '%d.%06ds' % (
|
||||
delta.days * DAY_SECONDS + delta.seconds, delta.microseconds)
|
||||
return duration
|
||||
|
||||
def run_time(self):
|
||||
runtime = 0.0
|
||||
for name, data in self.results.items():
|
||||
runtime += float(self.get_duration(data['start_time'],
|
||||
data['end_time']).strip('s'))
|
||||
return runtime
|
||||
|
@ -51,7 +51,7 @@ def parse_args(argv, default_config_files=None):
|
||||
|
||||
def process_results(results):
|
||||
session = api.get_session()
|
||||
db_run = api.create_run()
|
||||
db_run = api.create_run(run_time=results.pop('run_time'))
|
||||
for test in results:
|
||||
db_test = api.get_test_by_test_id(test, session)
|
||||
if not db_test:
|
||||
|
Loading…
x
Reference in New Issue
Block a user