Skip to content

Commit

Permalink
Merge pull request #232 from buildkite-plugins/fix-slowest-test-run
Browse files Browse the repository at this point in the history
Update command to fix annotation for slowest tests
  • Loading branch information
nsuma8989 authored Nov 6, 2024
2 parents 5f6d728 + 25ed933 commit 141711e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hooks/command
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ if [ $has_errors -eq 0 ]; then
create_annotation=1
fi

if [[ -n "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST:-}" ]]; then
echo "Create annotation with slowest tests"
create_annotation=1
fi

if [[ -e "${annotation_path}" ]]; then
TOTAL_TESTS=$(head -5 "${annotation_path}" | grep 'Total tests' | cut -d\ -f3)
else
Expand Down
18 changes: 18 additions & 0 deletions tests/2-slowest-tests.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Failures: 0
Errors: 0
Skipped: 0
Total tests: 8

<details>
<summary>5 slowest tests</summary>
<table>
<thead><tr><th>Unit</th><th>Test</th><th>Time</th></tr></thead>
<tbody>
<tr><td>spec.models.account_spec</td><td>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default</td><td>0.977127</td></tr>
<tr><td>spec.models.account_spec</td><td>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default</td><td>0.967127</td></tr>
<tr><td>spec.models.account_spec</td><td>Account#maximum_jobs_added_by_pipeline_changer returns 500 if the account is ABC</td><td>0.620013</td></tr>
<tr><td>spec.models.account_spec</td><td>Account#maximum_jobs_added_by_pipeline_changer returns 900 if the account is F00</td><td>0.520013</td></tr>
<tr><td>spec.models.account_spec</td><td>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ</td><td>0.420013</td></tr>
</tbody>
</table>
</details>
28 changes: 28 additions & 0 deletions tests/command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,31 @@ DOCKER_STUB_DEFAULT_OPTIONS='--log-level error run --rm --volume \* --volume \*
unstub docker
rm "${annotation_input}"
}

@test "creates annotation with no failures but with slowest tests trigger" {
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST=5

stub mktemp \
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"

stub buildkite-agent \
"artifact download \* \* : echo Downloaded artifact \$3 to \$4" \
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"

stub docker \
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST=5 --env \* \* ruby /src/bin/annotate /junits : cat tests/2-slowest-tests.output"

run "$PWD/hooks/command"

assert_success

assert_output --partial "Create annotation with slowest tests"
assert_output --partial "<summary>5 slowest tests</summary>"

unstub mktemp
unstub buildkite-agent
unstub docker
rm "${annotation_input}"
}

0 comments on commit 141711e

Please sign in to comment.