Skip to content

Commit e3488be

Browse files
committed
Make sure e2e tests reports are uploaded on failure (#6607)
This makes sure e2e tests reports are uploaded on failure with 2 changes: * the JSON go test results are uploaded regardless of the status of the make e2e-run command * a new step is run to download all test results and convert them to JUnit XML reports JUnit XML reports are uploaded temporarily waiting we build a Buildkite annotation to summarize the test failures.
1 parent f2c3806 commit e3488be

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

.buildkite/e2e/pipeline-gen/pipeline.tpl.yaml

+14-5
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,11 @@ steps:
6666
{{- end }}
6767

6868
{{- if $test.Dind }}
69-
- make -C .ci TARGET="{{ $deployerCommand }} e2e-run e2e-generate-xml" ci
69+
- make -C .ci TARGET="{{ $deployerCommand }} e2e-run" ci
7070
{{- else }}
71-
- make {{ $deployerCommand }} e2e-run e2e-generate-xml
71+
- make {{ $deployerCommand }} e2e-run
7272
{{- end }}
7373

74-
- mkdir tests-report && mv e2e-tests.xml tests-report/e2e-tests-{{ $test.SlugName }}.xml
75-
7674
agents:
7775
{{- if $test.Dind }}
7876
provider: "gcp"
@@ -85,7 +83,7 @@ steps:
8583
{{- end }}
8684

8785
artifact_paths:
88-
- tests-report/*.xml
86+
- e2e-tests-*.json
8987
- "eck-diagnostic*.zip"
9088

9189
{{- end }}
@@ -123,6 +121,17 @@ steps:
123121
image: "family/elastic-buildkite-agent-ubuntu-2004-lts"
124122
{{- end }}
125123

124+
125+
126126
{{- end }}
127127
{{- end }}
128128

129+
- wait: ~
130+
continue_on_failure: true
131+
132+
- label: aggregate tests-results
133+
commands:
134+
- buildkite-agent artifact download e2e-tests-*.json .
135+
- .buildkite/scripts/test/generate-tests-reports.sh
136+
artifact_paths:
137+
- e2e-tests-*.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4+
# or more contributor license agreements. Licensed under the Elastic License 2.0;
5+
# you may not use this file except in compliance with the Elastic License 2.0.
6+
7+
# Script to generate e2e tests reports in JUnit XML format from JSON go test results.
8+
9+
set -eu
10+
11+
gen_junit_report() {
12+
local input_file=${1:-"input file"}
13+
local xml_report=${input_file%.*}.xml
14+
15+
# exit without error when there is no input file
16+
if [[ ! -f $input_file ]]; then
17+
echo "No $input_file to generate a JUnit XML report."
18+
exit 0
19+
fi
20+
21+
# temporary filter out lines containing a space in the timestamp,
22+
# see https://github.com/elastic/cloud-on-k8s/issues/3560.
23+
gotestsum \
24+
--junitfile "$xml_report" \
25+
--raw-command grep -v '"Time":"[^"]*\s[^"]*"' "$input_file" || \
26+
( \
27+
echo "Failed to generate a JUnit XML report."
28+
# print the input file for further debugging
29+
echo " --- $input_file - START ---"
30+
cat "$input_file"
31+
echo " --- $input_file - END ---"
32+
exit 1
33+
)
34+
}
35+
36+
for f in e2e-tests-*.json; do
37+
gen_junit_report "$f"
38+
done

test/e2e/cmd/run/run.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ import (
3535
)
3636

3737
const (
38-
jobTimeout = 600 * time.Minute // time to wait for the test job to finish
39-
kubePollInterval = 10 * time.Second // Kube API polling interval
40-
testRunLabel = "test-run" // name of the label applied to resources
41-
logStreamLabel = "stream-logs" // name of the label enabling log streaming to e2e runner
42-
testsLogFile = "e2e-tests.json" // name of file to keep all test logs in JSON format
43-
operatorReadyTimeout = 3 * time.Minute // time to wait for the operator pod to be ready
38+
jobTimeout = 600 * time.Minute // time to wait for the test job to finish
39+
kubePollInterval = 10 * time.Second // Kube API polling interval
40+
testRunLabel = "test-run" // name of the label applied to resources
41+
logStreamLabel = "stream-logs" // name of the label enabling log streaming to e2e runner
42+
testsLogFilePattern = "e2e-tests-%s.json" // name of file to keep all test logs in JSON format
43+
operatorReadyTimeout = 3 * time.Minute // time to wait for the operator pod to be ready
4444

4545
TestNameLabel = "test-name" // name of the label applied to resources during each test
4646
)
@@ -602,7 +602,7 @@ func (h *helper) startAndMonitorTestJobs(client *kubernetes.Clientset) error {
602602

603603
outputs := []io.Writer{os.Stdout}
604604
if h.logToFile {
605-
jl, err := newJSONLogToFile(testsLogFile)
605+
jl, err := newJSONLogToFile(fmt.Sprintf(testsLogFilePattern, h.testContext.ClusterName))
606606
if err != nil {
607607
log.Error(err, "Failed to create log file for test output")
608608
return err

0 commit comments

Comments
 (0)