-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🐛 [Bug]: Isolation Issue with Parallel Subtests #2871
Comments
We should also detect the shared stuff between tests. Something may be wrong or just false positive. Btw i agree about setupApp. Maybe we can create something like helper to reduce code duolication on tests/benchmarks |
A similar problem was just noticed in internal/storage/memory/memory_test.go where |
we should investigate these cases and, in my opinion, not simply fix them through isolation because normally it is a valid setup |
https://github.com/gofiber/fiber/blob/v2/ctx_test.go#L1376-L1467 |
we found the problem, If you take it out of the pool again it's bad Will fix it tomorrow or the day after, so not isolating it has shown us a real world bug which also occurs in a real application when ctx is not completely recreated, but is reused from the pool |
v2 Line 181 in ddc6b23
Line 193 in ddc6b23
v3 Lines 446 to 452 in 26346d6
Lines 455 to 458 in 26346d6
Line 489 in 26346d6
The problem here is that the fasthttp context is only set when new items are created for the pool, but not when items from the pool are reused, so we would have to move this to AcquireCtx Lines 497 to 501 in 26346d6
We should also examine this process again Lines 461 to 484 in 26346d6
|
We also have to use the code of the Reset method in the AcquireCtx |
I appreciate the thoughtful discussion. My intention in raising the issue was to address what appeared to be false positives [failures] in the unit tests. I understand the importance of considering the validity of shared resources and agree that fixing the underlying problem was crucial. I didn't mean to suggest avoiding further investigation into the root cause. What occurred to me is that the failures might be signaling a need for more granular unit testing with greater isolation, but I acknowledge that this approach could be impractical. Achieving effective coverage using more isolated unit tests could lead to requiring an extensive set of additional tests, covering such interaction scenarios with concurrency and other complexities. The current tests, though indirectly, did help identify an issue. Thanks for your understanding. Open to further insights or discussion. |
I think there are two important points to take home.
It seems to me that it might be good to at the very least comb over the existing tests to make sure that we are addressing both points. Given how many tests there are, that would probably be a lot of work. |
@nickajacks1 I'm planning on starting to take a look at the benchmarks for the core and the middlewares. Several middlewares are missing Benchmarks. We also need to add Will start tomorrow with 1-2 of them to see if anything raises, we can go from there. |
I have made almost all tests work with |
bug fixed with 5a0167a |
This is mostly fix by #2892 I'm going to double check today how many tests are not parallel. |
ok then no need for keeping this open |
An issue that appears throughout the tests. Running tests in parallel using the
t.Parallel()
function can show problems when the tests that are not isolated. When tests share a state, such as a common instance ofapp
, running them in parallel can lead to race conditions or other unexpected behavior leading to unpredictable results.To fix this issue [with false results in tests], we could refactor the tests and make sure that each test has its isolated state.
If we want to eliminate repetitive code for setup and teardown for each parallel test, we could consider using the testify/suite package.
For example I ran into issues with the
Test_Client_UserAgent
.Example, Test_Client_UserAgent original:
Originally posted by @sixcolors in #2864 (comment)
The issues found in three test files, namely app_test.go, client_test.go, and ctx_test.go.
The text was updated successfully, but these errors were encountered: