Skip to content

Commit a370a7c

Browse files
committed
[report_result] Add testcase error detection and reporting
Previously, report_result.yml only checked for testcase failures but ignored errors in the JUnit XML output. This meant that tests could error out without causing the CI job to fail. This change adds: - Extraction of 'errors' count from XML testsuites - Failure task that triggers when errors > 0 This ensures both failures and errors in testcases are properly reported and cause the CI job to fail as expected.
1 parent b50bac6 commit a370a7c

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

ci/report_result.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,30 @@
3535
register: verbose_matches
3636
ignore_errors: true
3737

38+
# The RC from grep is 2 if an error occurred.
39+
- name: Fail if the file was not found (or other grep error)
40+
ansible.builtin.fail:
41+
msg: "{{ verbose_matches.stderr if verbose_matches.stderr | length > 0 else 'There was an error with grep.' }}"
42+
when: verbose_matches.rc > 1
43+
3844
- name: "Fail if there are no XML files"
3945
ansible.builtin.fail:
4046
msg: "There were no XML files found in {{ logs_dir }}."
4147
when: verbose_matches.stdout_lines | length == 0
4248

43-
- name: "Get the number of failed testcases"
49+
- name: "Get the number of testcase errors and failures"
4450
ansible.builtin.set_fact:
51+
tasks_errored: "{{ verbose_matches.stdout | regex_replace('.*errors=\"([0-9]*)\".*>', '\\1') | split('\n') | map('int') | sum }}"
4552
tasks_failed: "{{ verbose_matches.stdout | regex_replace('.*failures=\"([0-9]*)\".*>', '\\1') | split('\n') | map('int') | sum }}"
4653

4754
# The RC from grep is 0 if the string is matched
48-
- name: Fail when there's a testcase failure
55+
- name: Fail when there's a testcase error
4956
ansible.builtin.fail:
50-
msg: There were {{ tasks_failed }} failed testcases.
51-
when: tasks_failed | int > 0 and verbose_matches.rc == 0
57+
msg: There were {{ tasks_errored }} errors in the testcases.
58+
when: tasks_errored | int > 0 and verbose_matches.rc == 0
5259

53-
- name: Determine success or failure based on the number of failed tasks
54-
ansible.builtin.fail:
55-
msg: "The log file(s) contain failed task."
56-
when: tasks_failed | int > 0 and verbose_matches.rc == 0
57-
58-
# The RC from grep is 2 if an error occurred.
59-
- name: Fail if the file was not found (or other grep error)
60+
# The RC from grep is 0 if the string is matched
61+
- name: Fail when there's a testcase failure
6062
ansible.builtin.fail:
61-
msg: "{{ verbose_matches.stderr if verbose_matches.stderr | length > 0 else 'There was an error with grep.' }}"
62-
when: verbose_matches.rc > 1
63+
msg: There were {{ tasks_errored }} errors and {{ tasks_failed }} failed testcases.
64+
when: ( [ tasks_failed, tasks_errored ] | sum > 0 ) and verbose_matches.rc == 0

0 commit comments

Comments
 (0)