Skip to content

Commit

Permalink
fix regressions on multiple tests suites
Browse files Browse the repository at this point in the history
The legacy code assumes that there is only
one junit file. When there is several files
it doesn't compare the correct ones,
eg: Rally vs Tempest, which prevent to find
regression.

Change-Id: I285561ef8ef8e7228a20e9d7c64b4968058568c9
  • Loading branch information
ylamgarchal committed Oct 25, 2018
1 parent 448f646 commit 8dd9e00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 5 additions & 3 deletions dci/api/v1/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ def get_previous_job_in_topic(job):
return flask.g.db_conn.execute(query).fetchone()


def _get_test_result_of_previous_job(job):
def _get_test_result_of_previous_job(job, filename):
prev_job = get_previous_job_in_topic(job)
if prev_job is None:
return None
query = sql.select([models.TESTS_RESULTS]). \
where(models.TESTS_RESULTS.c.job_id == prev_job['id'])
where(sql.and_(models.TESTS_RESULTS.c.job_id == prev_job['id'],
models.TESTS_RESULTS.c.name == filename))
res = flask.g.db_conn.execute(query).fetchone()
if res is not None:
res = dict(res)
Expand Down Expand Up @@ -155,7 +156,8 @@ def create_files(user):
if values['mime'] == 'application/junit':
_, file_descriptor = swift.get(file_path)
jsonunit = tsfm.junit2dict(file_descriptor.read())
prev_test_result = _get_test_result_of_previous_job(job)
prev_test_result = _get_test_result_of_previous_job(job,
values['name'])
if prev_test_result is not None:
prev_test_result['testscases'] = prev_test_result['tests_cases'] # noqa
if len(prev_test_result['testscases']) > 0:
Expand Down
21 changes: 19 additions & 2 deletions tests/api/v1/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,30 @@ def get_file_content(filename):
tests_data.jobtest_without_failures),
mime='application/junit')
assert f_1 is not None
t_utils.post_file(admin, jobstate_1['id'],
FileDesc('Rally',
tests_data.jobtest_without_failures),
mime='application/junit')

f_2 = t_utils.post_file(admin, jobstate_2['id'],
FileDesc('Tempest',
tests_data.jobtest_with_failures),
mime='application/junit',
swift_get_mock=swift_get_mock)
assert f_2 is not None
t_utils.post_file(admin, jobstate_2['id'],
FileDesc('Rally',
tests_data.jobtest_without_failures),
mime='application/junit')

# 4. verify regression in job_2's result which is 'test_3'
job_2_results = admin.get(
'/api/v1/jobs/%s?embed=results' % job_2['id']).data['job']['results']
assert job_2_results[0]['regressions'] == 1
for job_res in job_2_results:
if job_res['name'] == 'Tempest':
assert job_res['regressions'] == 1
elif job_res['name'] == 'Rally':
assert job_res['regressions'] == 0

# 4. get the job2's tests results
with mock.patch(SWIFT, spec=Swift) as mock_swift:
Expand All @@ -133,7 +145,12 @@ def get_file_content(filename):
job_2_tests_results = admin.get(
'/api/v1/jobs/%s/results' % job_2['id'])

testcases = job_2_tests_results.data['results'][0]['testscases']
# get Tempest result
testcases = job_2_tests_results.data['results'][0]
if testcases['name'] == 'Tempest':
testcases = job_2_tests_results.data['results'][0]['testscases']
else:
testcases = job_2_tests_results.data['results'][1]['testscases']

regression_found = False
for testcase in testcases:
Expand Down

0 comments on commit 8dd9e00

Please sign in to comment.