Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@raisaat
Copy link
Contributor

@raisaat raisaat commented Aug 3, 2021

What type of PR is this?

What this PR does / why we need it:

This PR adds unit tests for the crio_processes_defunct metric. It also changes the function DefunctProcesses to DefunctProcessesForPath in internal/process/defunct_processes.go to take the path name of a filesystem as a parameter and adds DefunctProcesses as 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/testing which consists of several other directories and a file to account for different test cases.

Does this PR introduce a user-facing change?


@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 3, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 3, 2021

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 /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.

Details

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.

@openshift-ci openshift-ci bot requested review from kolyshkin and nalind August 3, 2021 18:58
@codecov
Copy link

codecov bot commented Aug 3, 2021

Codecov Report

Merging #5161 (197ff69) into master (5ab85f5) will increase coverage by 0.21%.
The diff coverage is 83.33%.

@@            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     

Comment on lines 1 to 12
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)
}
}
Copy link
Member

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.

@raisaat raisaat force-pushed the test-defunct branch 3 times, most recently from ca4afd9 to 8770651 Compare August 5, 2021 02:45
Copy link
Member

@saschagrunert saschagrunert left a 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")
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
RunFrameworkSpecs(t, "DefunctProcesses")
RunFrameworkSpecs(t, "Process")

Comment on lines 11 to 12
// TestDefunctProcessesForPath runs the created specs
func TestDefunctProcessesForPath(t *testing.T) {
Copy link
Member

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:

Suggested change
// TestDefunctProcessesForPath runs the created specs
func TestDefunctProcessesForPath(t *testing.T) {
// TestProcess runs the created specs
func TestProcess(t *testing.T) {

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 5, 2021
@saschagrunert saschagrunert marked this pull request as ready for review August 5, 2021 07:56
@saschagrunert
Copy link
Member

/ok-to-test

@openshift-ci openshift-ci bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 5, 2021
@saschagrunert
Copy link
Member

/release-note-none

@openshift-ci openshift-ci bot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Aug 5, 2021
@saschagrunert
Copy link
Member

/test e2e_rhel

…ocesses.go for the unit test

Signed-off-by: Raisaat Rashid <[email protected]>
@raisaat raisaat changed the title [WIP] Unit Test For Defunct Processes Metric Unit Test For Defunct Processes Metric Aug 5, 2021
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 5, 2021
@haircommander haircommander added this to the 1.22 milestone Aug 5, 2021
// 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)
Copy link

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)

Copy link
Contributor

@TomSweeneyRedHat TomSweeneyRedHat left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 6, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 6, 2021

[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

Details 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

@saschagrunert
Copy link
Member

/retest

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 6, 2021

@raisaat: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Rerun command
ci/openshift-jenkins/e2e_crun_cgroupv2 197ff69 link /test e2e_cgroupv2

Full PR test history. Your PR dashboard.

Details

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. I understand the commands that are listed here.

@openshift-bot
Copy link

/retest-required

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci openshift-ci bot merged commit 6092081 into cri-o:master Aug 7, 2021
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. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants