Skip to content

fix race in unit test and add some simple tests for utils #732

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

Merged
merged 3 commits into from
Aug 13, 2022

Conversation

avoltz
Copy link
Contributor

@avoltz avoltz commented Aug 12, 2022

What type of PR is this?

/kind test

What this PR does / why we need it:

Add some coverage to pkg/util tests.

Fix a race in csi-common test, described in commit text:

    Without this fix, running `go test -race -count 10` causes this failure:

    /var/folders/py/rwp4m4k977l9stj_f2kqrmxw000_5c/T/go-build3764188957/b001/csi-common.test flag redefined: log_dir
    --- FAIL: TestLogGRPC (0.00s)
    panic: /var/folders/py/rwp4m4k977l9stj_f2kqrmxw000_5c/T/go-build3764188957/b001/csi-common.test flag redefined: log_dir [recovered]
            panic: /var/folders/py/rwp4m4k977l9stj_f2kqrmxw000_5c/T/go-build3764188957/b001/csi-common.test flag redefined: log_dir

    goroutine 70 [running]:
    testing.tRunner.func1.2({0x17a37e0, 0xc0000b4180})
            /usr/local/Cellar/go/1.18.5/libexec/src/testing/testing.go:1389 +0x366
    testing.tRunner.func1()
            /usr/local/Cellar/go/1.18.5/libexec/src/testing/testing.go:1392 +0x5d2
    panic({0x17a37e0, 0xc0000b4180})
            /usr/local/Cellar/go/1.18.5/libexec/src/runtime/panic.go:844 +0x258
    flag.(*FlagSet).Var(0xc00020c120, {0x19668c0, 0x1d00f90}, {0x186cfd4, 0x7}, {0x188d879, 0x52})
            /usr/local/Cellar/go/1.18.5/libexec/src/flag/flag.go:879 +0x3a5
    flag.(*FlagSet).StringVar(...)
            /usr/local/Cellar/go/1.18.5/libexec/src/flag/flag.go:762
    k8s.io/klog/v2.InitFlags(0x0)
            /Users/avoltz/src/blob-csi-driver/vendor/k8s.io/klog/v2/klog.go:424 +0xee
    sigs.k8s.io/blob-csi-driver/pkg/csi-common.TestLogGRPC(0xc0000829c0)
            /Users/avoltz/src/blob-csi-driver/pkg/csi-common/utils_test.go:87 +0x45
    testing.tRunner(0xc0000829c0, 0x18ae070)
            /usr/local/Cellar/go/1.18.5/libexec/src/testing/testing.go:1439 +0x214
    created by testing.(*T).Run
            /usr/local/Cellar/go/1.18.5/libexec/src/testing/testing.go:1486 +0x725
    FAIL    sigs.k8s.io/blob-csi-driver/pkg/csi-common      4.298s
    FAIL

Which issue(s) this PR fixes:

Fixes #

Requirements:

Special notes for your reviewer:

Release note:

none

Without this fix, running `go test -race -count 10` causes this failure:

/var/folders/py/rwp4m4k977l9stj_f2kqrmxw000_5c/T/go-build3764188957/b001/csi-common.test flag redefined: log_dir
--- FAIL: TestLogGRPC (0.00s)
panic: /var/folders/py/rwp4m4k977l9stj_f2kqrmxw000_5c/T/go-build3764188957/b001/csi-common.test flag redefined: log_dir [recovered]
	panic: /var/folders/py/rwp4m4k977l9stj_f2kqrmxw000_5c/T/go-build3764188957/b001/csi-common.test flag redefined: log_dir

goroutine 70 [running]:
testing.tRunner.func1.2({0x17a37e0, 0xc0000b4180})
	/usr/local/Cellar/go/1.18.5/libexec/src/testing/testing.go:1389 +0x366
testing.tRunner.func1()
	/usr/local/Cellar/go/1.18.5/libexec/src/testing/testing.go:1392 +0x5d2
panic({0x17a37e0, 0xc0000b4180})
	/usr/local/Cellar/go/1.18.5/libexec/src/runtime/panic.go:844 +0x258
flag.(*FlagSet).Var(0xc00020c120, {0x19668c0, 0x1d00f90}, {0x186cfd4, 0x7}, {0x188d879, 0x52})
	/usr/local/Cellar/go/1.18.5/libexec/src/flag/flag.go:879 +0x3a5
flag.(*FlagSet).StringVar(...)
	/usr/local/Cellar/go/1.18.5/libexec/src/flag/flag.go:762
k8s.io/klog/v2.InitFlags(0x0)
	/Users/avoltz/src/blob-csi-driver/vendor/k8s.io/klog/v2/klog.go:424 +0xee
sigs.k8s.io/blob-csi-driver/pkg/csi-common.TestLogGRPC(0xc0000829c0)
	/Users/avoltz/src/blob-csi-driver/pkg/csi-common/utils_test.go:87 +0x45
testing.tRunner(0xc0000829c0, 0x18ae070)
	/usr/local/Cellar/go/1.18.5/libexec/src/testing/testing.go:1439 +0x214
created by testing.(*T).Run
	/usr/local/Cellar/go/1.18.5/libexec/src/testing/testing.go:1486 +0x725
FAIL	sigs.k8s.io/blob-csi-driver/pkg/csi-common	4.298s
FAIL
@k8s-ci-robot k8s-ci-robot added kind/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 12, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @avoltz. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 12, 2022
@andyzhangx
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot 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 13, 2022
Copy link
Member

@andyzhangx andyzhangx left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 13, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx, avoltz

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 13, 2022
@k8s-ci-robot k8s-ci-robot merged commit 7997c36 into kubernetes-sigs:master Aug 13, 2022
@avoltz avoltz deleted the anvoltz/ut-fixes branch August 13, 2022 14:00
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/test lgtm "Looks good to me", 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants