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

Save test results for each test spec to improve test results reporting #5449

Merged

Conversation

rnapoles-rh
Copy link
Contributor

What type of PR is this:

/kind tests

What does this PR do / why we need it:
Updated CommonAfterEach to save test results for each test spec to improve test results reporting.
Will work in conjunction with the test pipeline to update cumulative test results file to IBM cloud bucket

Which issue(s) this PR fixes:
No related issue

Fixes #5430

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:

@netlify
Copy link

netlify bot commented Feb 9, 2022

✔️ Deploy Preview for odo-docusaurus-preview canceled.

🔨 Explore the source changes: a9431f8

🔍 Inspect the deploy log: https://app.netlify.com/sites/odo-docusaurus-preview/deploys/6228e61026acd3000ae3bc89

@odo-robot
Copy link

odo-robot bot commented Feb 9, 2022

Unit Tests on commit c4ec202 finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Feb 9, 2022

Validate Tests on commit c4ec202 finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Feb 9, 2022

OpenShift Tests on commit c4ec202 finished with errors.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Feb 9, 2022

Kubernetes Tests on commit c4ec202 finished with errors.
View logs: TXT HTML

tests/helper/helper_generic.go Outdated Show resolved Hide resolved
tests/helper/helper_generic.go Outdated Show resolved Hide resolved
tests/helper/helper_generic.go Outdated Show resolved Hide resolved
Comment on lines +317 to +325
commonVar.testFailed = CurrentGinkgoTestDescription().Failed
commonVar.testDuration = CurrentGinkgoTestDescription().Duration.Seconds()
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't these things go in CommonAfterEach()? How can you know the duration the test took to run and it's pass/fail status before it is run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I moved them to CommonAfterEach()

tests/helper/helper_generic.go Outdated Show resolved Hide resolved
@kadel kadel added area/testing Issues or PRs related to testing, Quality Assurance or Quality Engineering and removed kind/tests labels Feb 16, 2022
Copy link
Member

@valaparthvi valaparthvi 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 the changes! And sorry for late review.

Comment on lines 346 to 350
if _, err = f.WriteString(resultsRow); err != nil {
fmt.Println("Error: ", err)
}

f.Close()
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this block be only called when L341-344 does not end in error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, change made.

@odo-robot
Copy link

odo-robot bot commented Feb 24, 2022

Windows Tests (OCP) on commit c4ec202 finished with errors.
View logs: TXT HTML

if err != nil {
fmt.Println("Error: ", err)
} else {
defer f.Close()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
defer f.Close()
defer f.Close() //#nosec

This should fix the unit test failure, or optionally you can remove this defer.
This issue has been reported in securego/gosec#714, so perhaps we can update the gosec library and see if that helps. For a quick fix, you can implement the above suggestions.

Comment on lines 347 to 354
if _, err = f.WriteString(resultsRow); err != nil {
fmt.Println("Error: ", err)
}
f.Close()
}

Copy link
Member

Choose a reason for hiding this comment

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

Optional:

Suggested change
if _, err = f.WriteString(resultsRow); err != nil {
fmt.Println("Error: ", err)
}
f.Close()
}
_, err = f.WriteString(resultsRow)
if err != nil {
fmt.Println("Error: ", err)
}
if err = f.Close(); err != nil {
fmt.Println("Error: ", err)
}

Since we are performing write operation, it is advised that it is done in a separate line, because it makes some changes, for a normal read operation, an inline read and error check is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggestion applied

@rnapoles-rh
Copy link
Contributor Author

/test v4.9-integration-e2e

if err != nil {
fmt.Println("Error: ", err)
} else {
f.Close()
Copy link
Member

Choose a reason for hiding this comment

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

If you close the file, you will not be able to write to it, please remove f.Close() from line 346.

Copy link
Member

Choose a reason for hiding this comment

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

It's a wide practice to use defer f.Close() so that the file will be closed as the last thing before go runtime is done with this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that f.close was left behind, removed.

}
testDate := strings.Split(time.Now().Format(time.RFC3339), "T")[0]
resultsRow = prNum + "," + testDate + "," + clusterType + "," + commonVar.testFileName + "," + commonVar.testCase + "," + passedOrFailed + "," + strconv.FormatFloat(commonVar.testDuration, 'E', -1, 64) + "\n"
testResultsFile := filepath.Join("/", "tmp", "testResults.txt")
Copy link
Contributor

Choose a reason for hiding this comment

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

What are we doing with this file? I assume this is not uploaded on any cloud storage bucket.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not yet, once this PR gets merged I will update the pipeline script to upload it to a bucket

Comment on lines 351 to 352
if err = f.Close(); err != nil {
fmt.Println("Error: ", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think if you do what Dharmit suggested in this comment, I think you can remove this portion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

followed Parthvi's suggestion as the defer was causing unit tests to fail. Now last thing I do in the after each is closing the file.

Copy link
Member

@valaparthvi valaparthvi left a comment

Choose a reason for hiding this comment

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

Code lgtm. @anandrkskd leaving it up to you to approve this.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Mar 7, 2022
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Mar 9, 2022
@sonarcloud
Copy link

sonarcloud bot commented Mar 9, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.6% 0.6% Duplication

@rnapoles-rh
Copy link
Contributor Author

timeout failure
/test v4.9-integration-e2e

@valaparthvi
Copy link
Member

/lgtm
/approve

Thank you for the PR, Rodolfo!

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Mar 10, 2022
@openshift-ci
Copy link

openshift-ci bot commented Mar 10, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: valaparthvi

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

The pull request process is described 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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. label Mar 10, 2022
@openshift-merge-robot openshift-merge-robot merged commit 53ef7f9 into redhat-developer:main Mar 10, 2022
cdrage pushed a commit to cdrage/odo that referenced this pull request Aug 31, 2022
redhat-developer#5449)

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* PoC to improve test results reporting

* Save test results for each spec to improve test results reporting

* Incorporated feedback from review

* Incorporated feedback from review

* Removed blank spaces after commas in data row

* Incorporated additional feedback

* Updated comment to rerun tests

* Incorporated feedback to fix unit tests failure and check for err during f.close

* Incorporated additional feedback on close command

* Edited comment to rerun tests

* Edited comment to rerun tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. area/testing Issues or PRs related to testing, Quality Assurance or Quality Engineering lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve test results reporting
6 participants