Skip to content

Conversation

listx
Copy link
Contributor

@listx listx commented Jun 13, 2023

This fixes some slightly-annoying things in the unit tests to reduce local unit-testing friction. It fixes some long-standing race conditions (including a real race in the GitHub client) as well as fixing a umask issue with file permissions which made one of the tests fail locally (but pass CI, because it is system-dependent).

We also enable the race detector with the -race flag by default.

/cc @cjwagner

@k8s-ci-robot k8s-ci-robot requested a review from cjwagner June 13, 2023 22:20
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. area/prow Issues or PRs related to prow sig/testing Categorizes an issue or PR as relevant to SIG Testing. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jun 13, 2023
@listx
Copy link
Contributor Author

listx commented Jun 14, 2023

/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 14, 2023
@listx listx changed the title cache_test: fix data race fix unit test issues Jun 14, 2023
@listx
Copy link
Contributor Author

listx commented Jun 14, 2023

/unhold
/cc @airbornepony

@k8s-ci-robot
Copy link
Contributor

@listx: GitHub didn't allow me to request PR reviews from the following users: airbornepony.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/unhold
/cc @airbornepony

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 removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 14, 2023
@listx
Copy link
Contributor Author

listx commented Jun 14, 2023

/cc @mpherman2

@k8s-ci-robot k8s-ci-robot requested a review from mpherman2 June 14, 2023 00:42
@listx listx changed the title fix unit test issues WIP: fix unit test issues Jun 14, 2023
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 14, 2023
@listx
Copy link
Contributor Author

listx commented Jun 14, 2023

Looks like there are some more quirks in CI vs my local system. Setting this as WIP for now while I work through the remaining test failures.

Linus Arver added 6 commits June 13, 2023 18:29
Previous to this change, on my development machine the TestCopy test
would fail as follows:

    $ ./hack/make-rules/go-test/unit.sh prow/cmd/entrypoint/...
    + mkdir -p /usr/local/google/home/linusa/go/src/k8s.io/test-infra/_output
    + /usr/local/google/home/linusa/go/src/k8s.io/test-infra/_bin/gotestsum --junitfile=/usr/local/google/home/linusa/go/src/k8s.io/test-infra/_output/junit-unit.xml -- -count=1 -race ./prow/cmd/entrypoint/...
    ✖  prow/cmd/entrypoint (27ms)

    === Failed
    === FAIL: prow/cmd/entrypoint TestCopy/base (0.00s)
    time="2023-06-13T17:19:59-07:00" level=info msg="src is /tmp/TestCopy3391565894/001/base"
        main_test.go:58: File mode mismatch. Want: -rw-r--r--, got: -rw-r-----
        --- FAIL: TestCopy/base (0.00s)

    === FAIL: prow/cmd/entrypoint TestCopy/another-mode (0.00s)
    time="2023-06-13T17:19:59-07:00" level=info msg="src is /tmp/TestCopy3391565894/001/another-mode"
        main_test.go:58: File mode mismatch. Want: -rwxr-xr-x, got: -rwxr-x---
        --- FAIL: TestCopy/another-mode (0.00s)

    === FAIL: prow/cmd/entrypoint TestCopy (0.00s)

    DONE 3 tests, 3 failures in 0.524s

This is because the file mode permissions that result are outside of
Go's control and is system-dependent (it's how POSIX works) [1]. This
change makes it so that we set umask to a standard value, 0022. The
manpage for the umask syscall says [2]:

    The typical default value for the process umask is
    S_IWGRP | S_IWOTH (octal 022).

[1] https://stackoverflow.com/a/41565509/437583
[2] https://man7.org/linux/man-pages/man2/umask.2.html
This way we can catch race conditions during development.
This was found by running

     go test -race k8s.io/test-infra/prow/cache
Previously we always tried to create the same key multiple times. This
was problematic because the cache size was 2, so we would never need to
evict a key (we'd never run out of room).
This was found by running

     go test -race k8s.io/test-infra/prow/github
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 14, 2023
@listx listx changed the title WIP: fix unit test issues fix unit test issues Jun 14, 2023
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 14, 2023
Copy link
Member

@petr-muller petr-muller left a comment

Choose a reason for hiding this comment

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

👍

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: listx, petr-muller

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 merged commit 8f8a2c8 into kubernetes:master Jun 21, 2023
mkdir -p "${JUNIT_RESULT_DIR}"
"${REPO_ROOT}/_bin/gotestsum" --junitfile="${JUNIT_RESULT_DIR}/junit-unit.xml" \
-- "./${folder_to_test}"
-- \
-race \
Copy link
Member

Choose a reason for hiding this comment

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

@listx it seems there is much more races in the codebase , so we need to fix all of them before enableing it

https://testgrid.k8s.io/presubmits-test-infra#unit-test&width=20

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. area/prow Issues or PRs related to prow cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/testing Categorizes an issue or PR as relevant to SIG Testing. 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