-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(tests): ensure tests using testutils.LogsUnderTestWithLogLevel() are not run in parallel
#5861
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(tests): ensure tests using testutils.LogsUnderTestWithLogLevel() are not run in parallel
#5861
Conversation
Ensure tests using using log capture with testutils are not run in parallel. Also changes some test to use the testutils package for log capture.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Hi @vflaux. 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 Once the patch is verified, the new status will be reflected by the 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-sigs/prow repository. |
|
The use case and the idea make sense to me. |
|
/ok-to-test |
|
Are there any data race issues with logging capture at the moment? The solution is a bit tricky, not sure if this is a recommended practice. The t.SetEnv() panic approach is brittle and could break with Go runtime changes, so it looks quite fragile. In future go version, it could be, that all tests will be running in parallel. So most likely instead we should be fixing data races where possible.
There are no examples that currently failing. But most recent issues I have witnessed where data races occur
|
|
I do agree that the implementation is not great. It would be better that the testing package exposed this. Maybe worth opening a proposal on the go project. I created this mainly to detect potential issues in the current codebase where log capture is used, and I wanted to share it. I don't have failing CI examples but I did encounter some issue while writing tests locally (fixed by removing t.Parallel).
It's a good example of a use case where checking if parallel execution is enabled of not would be useful. Testify could check and fail with a meaningful message in this case instead of reporting wrong results. While I'm not fully convinced that we should merge |
Here is golang/go#70017 I dunno. From my perspective as much as possible things should be immutable.
We not using singleton logger. Example external-dns/internal/testutils/log.go Line 38 in 6cf328f
Logrus library may have some data race issues. But I thought we did manage to fix all relevant issues in this codebase. |
|
If tests using |
|
Agree that there is still shared state. So why not to fix the design of those tests, but instead build hacks around the problem? Just to consider; Tests share unavoidable global state, and we are testing integration-like behavior Or for example, we do not need to change the log level for each tests, it could always be DEBUG, to catch all. It depends on what the “race” is, logger is global at the moment, and
If we still want to allow var logTestMu sync.Mutex
func TestLoggerIntegration(t *testing.T) {
logTestMu.Lock()
defer logTestMu.Unlock()
/....
}This change addresses the issue before the problem is actually made visible. Instead, we should make the data races reliably visible and reproducible in CI, ensuring consistency. Once the races are exposed in a reproducible way, we can then focus on implementing exact proposed fix or some other one. I'm not a huge fan of |
What does it do ?
Ensure tests using log capture with
testutils.LogsUnderTestWithLogLevel()are not run in parallel.Also changes some test to use the
testutilspackage for log capture.This introduce a helper function
testutils.IsParallel().A parallel test panic when
t.SetEnv()is called. This is used to determine if the test is marked to run in parallel or not.This is a hack as the
testingpackage do not expose this info.Motivation
Some tests that capture logs run in parallel which may cause tests to fails randomly.
More