-
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
Generalized Multinode unit tests BCI-2283 #11066
Generalized Multinode unit tests BCI-2283 #11066
Conversation
I see that you haven't updated any CHANGELOG files. Would it make sense to do so? |
I see that you haven't updated any README files. Would it make sense to do so? |
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.
Looks good to me. I can approve once changes are ready
13b8663
to
98cea17
Compare
IMO mocks should be moved to a separate folder because right now the client seems a bit too cluttered with all the mock files. |
Agree, but we'll have to keep |
Tried to implement it and not happy with the results. 5/8 mocks have to stay in the same package. It's still cluttered but now also more confusing, so I'd rather leave it as is. There is an open issue in mockery to generate all mocks into single file |
9452e36
to
71cec47
Compare
v3 looks like a major improvment https://github.com/vektra/mockery#v3 |
Would moving some interfaces into different packages (perhaps the type.go file) solve the issue? If not, can we at least drop the |
@@ -114,6 +95,7 @@ type multiNode[ | |||
leaseDuration time.Duration | |||
leaseTicker *time.Ticker | |||
chainFamily string | |||
reportInterval time.Duration |
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.
I don't see any benefits in storing the const variable here. I slightly prefer the old way. Also, we can avoid having to set it on the multi_node_test.go
(https://github.com/smartcontractkit/chainlink/pull/11066/files#diff-a9fee197ea880bb302ca4c0f830d292355586dca02d46c826becda641404cf30R232), since it's not used anywhere.
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.
Yes, const version is cleaner.
I've changed it to be able to override it in tests as original value is 6.5 seconds. Two tests has to wait for ticker to fire several times increasing total duration of tests from 4 seconds to ~13 seconds. This is not a lot for general run, but it makes flake tests hunting slightly more difficult as go test -n 100 ...
takes much more time to complete.
core/testutils/sync.go
Outdated
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.
Not sure why only some of them were moved here. If there aren't any blockers I would keep them under the same file or use the chainlink-relay
pkg.
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.
@dimriou do you mean merging logs.go and sync.go files or moving rest of the core/internal/testutils/testutils.go
to the core/testutils
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.
Three of these things exist in chailnink-relay/pkg/utils/tests
:
https://github.com/smartcontractkit/chainlink-relay/blob/02b76df27fb4369ee017ce5512df1f8041f1afce/pkg/utils/tests/tests.go
Edit: Oh this is the one I already commented on. I think @dimriou and I are saying the same thing. Priority is to not duplicate the ones you can just import. Separately we could consider moving some to chainlink-relay, but it's not necessary so nbd 🤷
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.
Ah this package is still in a weird place though. We can't tangle the imports up like this. We need to maintain the ability to move the common subtree out of this repo easily (and soon!). For that reason, it would be better to move these helpers to chainlink-relay.
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.
Moved missing parts to chainlink-relay and switched new tests to use it. @jmank88 Should I also deprecate testutils functions?
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.
Might want to wait since our linter is strict about using things marked deprecated.
core/internal/testutils/testutils.go
Outdated
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.
I've also made a comment below. This doesn't seem right. We just created multiple pass-through methods.
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.
The idea behind this function is to protect users from future changes/extensions to ID interface
Yes, we'll be able to generate mocks in separate package if we move Head, NodeClient, sendOnlyClient, connection. But it seems like reducing number of mock files in the package is not important enough to change the API. We can build some simple tool that would merge generated mock files into single file, but it's out of scope for this PR. We have to use _test suffix to ensure that |
8bd5418
to
9804373
Compare
assert.EqualError(t, err, expectedError.Error()) | ||
}) | ||
|
||
t.Run("Closes started nodes on failure", func(t *testing.T) { |
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.
I think this name is a bit misleading. During Dial
if a node tries to get started and it fails for any reason besides a wrong chainID, it will simply return an error. The node was never properly started to be closed. Perhaps something like this would be more accurate:
t.Run("Closes started nodes on failure", func(t *testing.T) { | |
t.Run("Fails if at least one node fails", func(t *testing.T) { |
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.
We test multinode failure on node failure above. Here the idea was to ensure that we properly release resources of node1, that was started if node2 fails. newHealthyNode
adds expectation of Close
call
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.
I see. newHealthyNode
seemed like a method that creates a mock node with the right configs. The expectation of Start
and Close
was a bit more difficult to figure out.
Co-authored-by: Dimitris Grigoriou <[email protected]>
# Conflicts: # core/scripts/go.mod # core/scripts/go.sum # go.mod # go.sum # integration-tests/go.mod # integration-tests/go.sum
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.
LGTM
SonarQube Quality Gate |
@@ -143,6 +146,7 @@ func (s *sendOnlyNode[CHAIN_ID, RPC]) start(startCtx context.Context) { | |||
func (s *sendOnlyNode[CHAIN_ID, RPC]) Close() error { | |||
return s.StopOnce(s.name, func() error { | |||
s.rpc.Close() | |||
close(s.chStop) |
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.
nit: was chStop being used before? Seems unused to me.
This PR is continuation of the efforts to generalize Multi-Node Failover logic:
core/chains/evm/client
tests tocommon/client
common/client
implementation to simplify testingcore/internal/testutils/testutils.go
to the new packagecore/testutils
to be able to use them incommon/client
.core/internal/testutils
API stays the same