-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix unit test issues #29797
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
fix unit test issues #29797
Conversation
/hold |
/unhold |
@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:
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. |
/cc @mpherman2 |
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. |
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
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.
👍
[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 |
mkdir -p "${JUNIT_RESULT_DIR}" | ||
"${REPO_ROOT}/_bin/gotestsum" --junitfile="${JUNIT_RESULT_DIR}/junit-unit.xml" \ | ||
-- "./${folder_to_test}" | ||
-- \ | ||
-race \ |
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.
@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
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