Skip to content

Commit b276a67

Browse files
committed
fix: use get_test_results() for commit status to prevent false-positive SUCCESS
1 parent 4a3b03d commit b276a67

1 file changed

Lines changed: 12 additions & 27 deletions

File tree

mod_ci/controllers.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,14 +2276,16 @@ def start_ci():
22762276
return json.dumps({'msg': 'EOL'})
22772277

22782278

2279-
def update_build_badge(status, test) -> None:
2279+
def update_build_badge(status, test, test_results=None) -> None:
22802280
"""
22812281
Build status badge for current test to be displayed on sample-platform.
22822282
22832283
:param status: current testing status
22842284
:type status: str
22852285
:param test: current commit that is tested
22862286
:type test: Test
2287+
:param test_results: pre-computed results from get_test_results; if None, fetched internally
2288+
:type test_results: list | None
22872289
:return: null
22882290
:rtype: null
22892291
"""
@@ -2294,7 +2296,8 @@ def update_build_badge(status, test) -> None:
22942296
shutil.copyfile(original_location, build_status_location)
22952297
g.log.info('Build badge updated successfully!')
22962298

2297-
test_results = get_test_results(test)
2299+
if test_results is None:
2300+
test_results = get_test_results(test)
22982301
test_ids_to_update = []
22992302
for category_results in test_results:
23002303
test_ids_to_update.extend([test['test'].id for test in category_results['tests'] if not test['error']])
@@ -2429,33 +2432,15 @@ def progress_type_request(log, test, test_id, request) -> bool:
24292432
message = 'Tests aborted due to an error; please check'
24302433

24312434
elif status == TestStatus.completed:
2432-
# Determine if success or failure
2433-
# It fails if any of these happen:
2434-
# - A crash (unexpected exit code)
2435-
# - A not None value on the "got" of a TestResultFile (
2436-
# meaning the hashes do not match)
2437-
crashes = g.db.query(count(TestResult.exit_code)).filter(
2438-
and_(
2439-
TestResult.test_id == test.id,
2440-
TestResult.exit_code != TestResult.expected_rc
2441-
)).scalar()
2442-
results_zero_rc = select(RegressionTest.id).filter(
2443-
RegressionTest.expected_rc == 0
2435+
test_results = get_test_results(test)
2436+
has_failures = any(
2437+
t['error']
2438+
for category in test_results
2439+
for t in category['tests']
24442440
)
2445-
results = g.db.query(count(TestResultFile.got)).filter(
2446-
and_(
2447-
TestResultFile.test_id == test.id,
2448-
TestResultFile.regression_test_id.in_(
2449-
results_zero_rc.select()
2450-
),
2451-
TestResultFile.got.isnot(None)
2452-
)
2453-
).scalar()
2454-
log.debug(f'[Test: {test.id}] Test completed: {crashes} crashes, {results} results')
2455-
if crashes > 0 or results > 0:
2441+
if has_failures:
24562442
state = Status.FAILURE
24572443
message = 'Not all tests completed successfully, please check'
2458-
24592444
else:
24602445
state = Status.SUCCESS
24612446
message = 'Tests completed'
@@ -2468,7 +2453,7 @@ def progress_type_request(log, test, test_id, request) -> bool:
24682453
message = 'All tests passed'
24692454
else:
24702455
message = 'Not all tests completed successfully, please check'
2471-
update_build_badge(state, test)
2456+
update_build_badge(state, test, test_results)
24722457

24732458
else:
24742459
message = progress.message

0 commit comments

Comments
 (0)