feat: Tests for IMC controller join/leave flow.#98
Conversation
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
e3512c4 to
8995fb6
Compare
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
d67d2ef to
63423c0
Compare
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
09e2182 to
2448787
Compare
Codecov upload limit reached
|
|
Fixing the data race issue: for the negative test cases(specs), there was no message sending to the imcChan (because the reconciliation doesn't succeed). Since chan blocks goroutine by default until both reader/ sender goroutine is ready (tour of Go), the goroutine that reads the chan causes data race when the imcchan var is reassigned in the next test. Close channel won't solve the problem as when the chan is reassigned, the goroutine picks up, as tested here: https://go.dev/play/p/kjKINIrdYak Solution is to have a sender for each reader of the chan and the other way around, as tested here: https://go.dev/play/p/8r8vTLexxRq So sending some message to imc chan fixes the issue. Some useful short readings:
|
|
The last commit is actually where I implemented the fix, although its name is |
Good learning! I don't really understand what the data race is though as the channel is closed at the end of each test. The only problem I see is that the channel is shared between two tests. Just separating them out should remove the so-called "race". |
-> This is where I scratched my head too as I thought the goroutine reading the chan should be closed (and never reopen) when the chan is closed. But now I think when the chan is closed then chan var is reassigned, the go routine that previously read the channel (BUT never receive any message) came alive again. I tested that behavior here: https://go.dev/play/p/8WXRykgyxPN If I sent some message to the chan the the behavior works as expected, as tested here: https://go.dev/play/p/kjKINIrdYak -> I agreed this setup ends up less straight forward than I thought so I don't really like it either. However I invested quite some time trying to create a completely new chan per test and it seems to be even messier as we needs to somehow setup the chan in BeforeEach but close in AfterEach without using a global variable like current setup. If there is a cleaner way I am down for changing. |
02a41dd to
8a711cc
Compare
There was a problem hiding this comment.
Clarification: Why are we sending the state as Leave here for the Join test?
There was a problem hiding this comment.
Short answer: We need to balance reader and writer goroutine for imc chan. This is after the test is done so what we send doesn't affect the test. I could create a nested context and put this in AfterEach but Ryan feedback in my last PR of a similar usage that it's not necessary.
Long answer: Details above of the error that happens when there is reader goroutine but no writer and vice versa.
|
Hey @minhng22 I don't think this part got tested in the Join workflow https://github.com/minhng22/fleet/blob/imc-controller-1/pkg/controllers/internalmembercluster/member_controller.go#L96-L99. Open question @ryanzhang-oss @helayoty are we expected to test this here since there are no unit tests to cover this as well. |
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
I am curious to know what other thinks. I don't include a test case for it in this PR to keep this PR smaller and be reviewed faster( but it seems like that doesn't help much). I could add a test case to cover that but I am not sure it's needed since the coverage is already above 90% while we decided 80% is enough. |
My preference is we close this PR regardless of whether we should add a test case for that, since this PR is getting too big, which makes it susceptible to more mistakes. Also the coverage is already higher than enough. |
Yes please, open a new PR. |
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
pkg/controllers/internalmembercluster/member_controller_integration_test.go
Outdated
Show resolved
Hide resolved
f5d4b46 to
66bf5ca
Compare
Description of your changes
Tests for IMC controller join/leave flow.
I have:
make reviewableto ensure this PR is ready for review.How has this code been tested
Coverage of test suite is 95.8% on member_controller.go
Special notes for your reviewer