Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Generate xUnit Reports for e2e tests #962

Open
wants to merge 36 commits into
base: master
Choose a base branch
from

Conversation

sawood14012
Copy link

a Wip PR which enables generation of junit/xunit reports to connect report-portal and Quality dashboard

Copy link

openshift-ci bot commented May 3, 2024

Hi @sawood14012. Thanks for your PR.

I'm waiting for a codeready-toolchain member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ranakan19
Copy link
Contributor

/ok-to-test

Copy link

openshift-ci bot commented May 15, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sawood14012
Once this PR has been reviewed and has the lgtm label, please assign matousjobanek for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look at this 🙏

I'm not familiar with go-junit-report but don't you need to pipe it to the go test ./... command as explained here:

go test -v 2>&1 ./... | go-junit-report -set-exit-code > report.xml

make/test.mk Outdated Show resolved Hide resolved
Meer Sawood and others added 2 commits May 15, 2024 17:49
Co-authored-by: Francisc Munteanu <fmuntean@redhat.com>
make/test.mk Outdated Show resolved Hide resolved
Meer Sawood and others added 2 commits May 21, 2024 12:54
Co-authored-by: Francisc Munteanu <fmuntean@redhat.com>
make/test.mk Show resolved Hide resolved
make/test.mk Outdated
Comment on lines 190 to 191
@command -v ./go-junit-report >/dev/null 2>&1 || { echo "go-junit-report is not installed. Installing..."; GOBIN=$(PWD) go install github.com/jstemmer/go-junit-report/v2@latest; }
@echo "go-junit-report version:" && ./go-junit-report -version
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather avoid installing the binary in the folder of the repository - let's install it either in /tmp folder or somewhere else.

make/test.mk Outdated
@@ -163,7 +165,8 @@ execute-tests:
@echo "Status of ToolchainStatus"
-oc get ToolchainStatus -n ${HOST_NS} -o yaml
@echo "Starting test $(shell date)"
MEMBER_NS=${MEMBER_NS} MEMBER_NS_2=${MEMBER_NS_2} HOST_NS=${HOST_NS} REGISTRATION_SERVICE_NS=${REGISTRATION_SERVICE_NS} go test ${TESTS_TO_EXECUTE} -run ${TESTS_RUN_FILTER_REGEXP} -p 1 -parallel ${E2E_PARALLELISM} -v -timeout=90m -failfast || \
$(MAKE) check-go-junit-report
MEMBER_NS=${MEMBER_NS} MEMBER_NS_2=${MEMBER_NS_2} HOST_NS=${HOST_NS} REGISTRATION_SERVICE_NS=${REGISTRATION_SERVICE_NS} go test ${TESTS_TO_EXECUTE} -run ${TESTS_RUN_FILTER_REGEXP} -p 1 -parallel ${E2E_PARALLELISM} -v -timeout=90m -failfast 2>&1 | $(MAKE) generate-report REPORT_NAME=${REPORT_NAME} || \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you cannot use the pipe for the whole output; otherwise, we will lose the content/output of the tests when running it locally as well as in openshift-ci

Copy link

sonarcloud bot commented Jun 14, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
3.4% Duplication on New Code

See analysis details on SonarCloud

@sawood14012
Copy link
Author

@MatousJobanek i have resolved your comments and updated my approach

  1. This approach ensures that the full output of the tests is retained and can be used both locally and in OpenShift CI.
  2. Also changed the dir of binary to /tmp
  3. the binary doesn't execute or generate a report locally.

@sawood14012 sawood14012 changed the title WIP: Generate xUnit Reports for e2e tests Core: Generate xUnit Reports for e2e tests Jun 20, 2024
make/test.mk Outdated
@echo "Skipping Go Junit report check and install"
endif
@echo "Running tests"
MEMBER_NS=${MEMBER_NS} MEMBER_NS_2=${MEMBER_NS_2} HOST_NS=${HOST_NS} REGISTRATION_SERVICE_NS=${REGISTRATION_SERVICE_NS} go test ${TESTS_TO_EXECUTE} -run ${TESTS_RUN_FILTER_REGEXP} -p 1 -parallel ${E2E_PARALLELISM} -v -timeout=90m -failfast 2>&1 | tee test_output.log
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_output.log should be stored in a /tmp folder, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

make/test.mk Outdated
Comment on lines 176 to 177
$(MAKE) generate-report REPORT_NAME=${REPORT_NAME} || \
($(MAKE) print-logs HOST_NS=${HOST_NS} MEMBER_NS=${MEMBER_NS} MEMBER_NS_2=${MEMBER_NS_2} REGISTRATION_SERVICE_NS=${REGISTRATION_SERVICE_NS} && exit 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is executed as a separate command, which means that printing logs will depend on the result of the generate-report target, not on the result of the tests.
The original way it was written printed out the logs only when the test failed and also returned the exit code 1, so execution of the print-logs target depended on the results of the tests - this needs to stay the same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so i am now running the generate report cmd after print logs hope this works

make/test.mk Outdated
Comment on lines 176 to 177
go test ${TESTS_TO_EXECUTE} -run ${TESTS_RUN_FILTER_REGEXP} -p 1 -parallel ${E2E_PARALLELISM} -v -timeout=90m -failfast 2>&1 | tee /tmp/test_output.log || ( $(MAKE) print-logs && exit 1 )
$(MAKE) generate-report REPORT_NAME=${REPORT_NAME}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the test fails, then the previous line exits with exit code 1, so the report won't be generated - see

|| ( $(MAKE) print-logs && exit 1 )

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that you need to do something like this:

Suggested change
go test ${TESTS_TO_EXECUTE} -run ${TESTS_RUN_FILTER_REGEXP} -p 1 -parallel ${E2E_PARALLELISM} -v -timeout=90m -failfast 2>&1 | tee /tmp/test_output.log || ( $(MAKE) print-logs && exit 1 )
$(MAKE) generate-report REPORT_NAME=${REPORT_NAME}
MEMBER_NS=${MEMBER_NS} MEMBER_NS_2=${MEMBER_NS_2} HOST_NS=${HOST_NS} REGISTRATION_SERVICE_NS=${REGISTRATION_SERVICE_NS} \
(go test ${TESTS_TO_EXECUTE} -run ${TESTS_RUN_FILTER_REGEXP} -p 1 -parallel ${E2E_PARALLELISM} -v -timeout=90m -failfast 2>&1 | tee /tmp/test_output.log && $(MAKE) generate-report REPORT_NAME=${REPORT_NAME}) || ( $(MAKE) print-logs && $(MAKE) generate-report REPORT_NAME=${REPORT_NAME} && exit 1 )

but I haven't tested it.
Not sure if there is some simpler way to deal with it

Copy link
Collaborator

@MatousJobanek MatousJobanek Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't work because of the pipe and the returned value from tee :-/

Comment on lines +175 to +179
MEMBER_NS=${MEMBER_NS} MEMBER_NS_2=${MEMBER_NS_2} HOST_NS=${HOST_NS} REGISTRATION_SERVICE_NS=${REGISTRATION_SERVICE_NS} \
go test ${TESTS_TO_EXECUTE} -run ${TESTS_RUN_FILTER_REGEXP} -p 1 -parallel ${E2E_PARALLELISM} -v -timeout=90m -failfast 2>&1 | tee /tmp/test_output.log; \
STATUS=$$?; \
$(MAKE) generate-report REPORT_NAME=${REPORT_NAME}; \
if [ $$STATUS -ne 0 ]; then $(MAKE) print-logs && exit 1; fi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested it and it doesn't work as expected - if one of the test suites fails, then it keeps running with the following test suites, but it should stop instead

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my guess is that STATUS=$$? takes the exit value from the tee command that is executed "after" the test as part of the pipe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of changing to STATUS=${PIPESTATUS[0]}; \ to capture the exit status of go test

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that could work, I didn't know about PIPESTATUS 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants