[controller] Fix bug in TestHandleUpdateClusterCreatesStatefulSets #235
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit fixes a bug in the logic of the
TestHandleUpdateClusterCreatesStatefulSets
test. The test checks that the controller creates all theStatefulSet
's in a new cluster. Previously, the test checked that all the expectedStatefulSet
's were created by checking the length of themap
that the test uses to trackStatefulSet
's that were created:However, when the test creates
expectedSetsCreated
it also inserts into it all theStatefulSet
's that it expects so the previousif
condition will always be true:This commit changes the test so it no longer adds the expected
StatefulSet
's toexpectedSetsCreated
after it's created, so the subsequent check on the length ofexpectedSetsCreated
will be valid because only theReactor
function will insert intoexpectedSetsCreated
.After making this change, however, I noticed that the tests were starting to fail. After some debugging, I realized this was because the
Reaction
function wastrue
. The documentation for it states:Since we were returning true, the next function in the chain, which would add it to the "fake" Kubernetes client we're using, never got called, so it would never be returned from subsequent calls to list the
StatefulSet
's and, as a result, we would continue retrying to create it.After changing the function to return false, I began encountering one final problem. Occasionally, the call to create a missing
StatefulSet
would return an error because theStatefulSet
we were trying to create already existed. It seemed this was a caching problem caused when the call to list theStatefulSet
's in the cluster didn't return the newStatefulSet
. To address this problem I updated the error handing after callingCreate
to check if the error was because theStatefulSet
already exists and to log and return nil if so.