-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Unit Test For Defunct Processes Metric #5161
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
Conversation
|
Hi @raisaat. Thanks for your PR. I'm waiting for a cri-o member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
Codecov Report
@@ Coverage Diff @@
## master #5161 +/- ##
==========================================
+ Coverage 43.91% 44.13% +0.21%
==========================================
Files 110 112 +2
Lines 11453 11533 +80
==========================================
+ Hits 5030 5090 +60
- Misses 5946 5957 +11
- Partials 477 486 +9 |
| package process | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestDefunctProcessesForPath(t *testing.T) { | ||
| defunctCount, err := DefunctProcessesForPath("./testing/proc") | ||
| if err != nil { | ||
| t.Errorf("%v", err) | ||
| } else if defunctCount != 7 { | ||
| t.Errorf("DefunctProcessesForPath returned %d; should return 7.", defunctCount) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is fine, let's use the ginkgo test framework like we do in other tests within this repository. This means, we add a suite_test.go like this: https://github.com/cri-o/cri-o/blob/master/internal/config/apparmor/suite_test.go
Then we modify the defunct_processes_test.go to this basic skeleton:
package process_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/cri-o/cri-o/internal/process"
)
// The actual test suite
var _ = t.Describe("Process", func() {
t.Describe("DefunctProcessesForPath", func() {
It("should succeed", func() {
defunctCount, err := process.DefunctProcessesForPath("./testing/proc")
Expect(err).To(BeNil())
Expect(defunctCount).To(Equal(7))
})
})
})Let's also add a tests for the err != nil cases.
ca4afd9 to
8770651
Compare
saschagrunert
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two nits, otherwise LGTM 👍
| // TestDefunctProcessesForPath runs the created specs | ||
| func TestDefunctProcessesForPath(t *testing.T) { | ||
| RegisterFailHandler(Fail) | ||
| RunFrameworkSpecs(t, "DefunctProcesses") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| RunFrameworkSpecs(t, "DefunctProcesses") | |
| RunFrameworkSpecs(t, "Process") |
| // TestDefunctProcessesForPath runs the created specs | ||
| func TestDefunctProcessesForPath(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's assume we're adding multiple tests to this:
| // TestDefunctProcessesForPath runs the created specs | |
| func TestDefunctProcessesForPath(t *testing.T) { | |
| // TestProcess runs the created specs | |
| func TestProcess(t *testing.T) { |
|
/ok-to-test |
|
/release-note-none |
|
/test e2e_rhel |
…ocesses.go for the unit test Signed-off-by: Raisaat Rashid <[email protected]>
| // DefunctProcessesForPath retrieves the number of zombie processes from | ||
| // a specific process filesystem. | ||
| func DefunctProcessesForPath(path string) (defunctCount uint, retErr error) { | ||
| directories, err := os.Open(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
G304: Potential file inclusion via variable
(at-me in a reply with help or ignore)
TomSweeneyRedHat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
saschagrunert
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: raisaat, saschagrunert The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest |
|
@raisaat: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. I understand the commands that are listed here. |
|
/retest-required Please review the full test history for this PR and help us cut down flakes. |
1 similar comment
|
/retest-required Please review the full test history for this PR and help us cut down flakes. |
What type of PR is this?
What this PR does / why we need it:
This PR adds unit tests for the
crio_processes_defunctmetric. It also changes the functionDefunctProcessestoDefunctProcessesForPathininternal/process/defunct_processes.goto take the path name of a filesystem as a parameter and addsDefunctProcessesas a wrapper for the function that passes the path name of the actual process filesystem,/proc, to it. This is needed for the unit tests as it allows to pass any filesystem for testing.Which issue(s) this PR fixes:
None
Special notes for your reviewer:
This PR adds a new directory
internal/process/testingwhich consists of several other directories and a file to account for different test cases.Does this PR introduce a user-facing change?