Skip to content

Commit 289048d

Browse files
committed
Fix tests
1 parent f93abf9 commit 289048d

6 files changed

Lines changed: 20 additions & 8 deletions

File tree

metrics/multinode_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func TestMultiNodeMetrics_LifecycleMetrics(t *testing.T) {
161161
m.SetHighestFinalizedBlock(ctx, nodeName, 456)
162162
require.InEpsilon(t,
163163
456.0,
164-
testutil.ToFloat64(promPoolRPCNodeHighestFinalizedBlock.WithLabelValues("test-network", "1", nodeName)),
164+
testutil.ToFloat64(PromPoolRPCNodeHighestFinalizedBlock.WithLabelValues("test-network", "1", nodeName)),
165165
0.001,
166166
)
167167
})

multinode/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/pkg/errors v0.9.1
1010
github.com/prometheus/client_model v0.6.1
1111
github.com/smartcontractkit/chainlink-common v0.7.0
12-
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250502183238-e20856f9c878
12+
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250502183956-f93abf9d14bc
1313
github.com/stretchr/testify v1.10.0
1414
go.uber.org/zap v1.27.0
1515
)

multinode/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR
7474
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
7575
github.com/smartcontractkit/chainlink-common v0.7.0 h1:QThOrHKn+du8CTmzJPCha0Nwnvw0tonIEAQca+dnmE0=
7676
github.com/smartcontractkit/chainlink-common v0.7.0/go.mod h1:pptbsF6z90IGCewkCgDMBxNYjfSOyW9X9l2jzYyQgmk=
77-
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250502183238-e20856f9c878 h1:yY+y9F/uzI/YbyGoHeqPzA6SdM+JDdRVsGWeuCuuIRw=
78-
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250502183238-e20856f9c878/go.mod h1:jo+cUqNcHwN8IF7SInQNXDZ8qzBsyMpnLdYbDswviFc=
77+
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250502183956-f93abf9d14bc h1:HXG3U4nWgzKtH8rjODkcbn4x2M2ZvD2jQotCWRpDM1Q=
78+
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250502183956-f93abf9d14bc/go.mod h1:jo+cUqNcHwN8IF7SInQNXDZ8qzBsyMpnLdYbDswviFc=
7979
github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298 h1:PKiqnVOTChlH4a4ljJKL3OKGRgYfIpJS4YD1daAIKks=
8080
github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298/go.mod h1:Mb7+/LC4edz7HyHxX4QkE42pSuov4AV68+AxBXAap0o=
8181
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

multinode/node_lifecycle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ func (n *node[CHAIN_ID, HEAD, RPC]) aliveLoop() {
120120
}
121121
lggr.Warnw(fmt.Sprintf("Poll failure, RPC endpoint %s failed to respond properly", n.String()), "err", err, "pollFailures", pollFailures, "nodeState", n.getCachedState())
122122
} else {
123-
n.metrics.RecordNodeClientVersion(ctx, n.name, version)
124123
lggr.Debugw("Ping successful", "nodeState", n.State())
124+
n.metrics.RecordNodeClientVersion(ctx, n.name, version)
125125
n.metrics.IncrementPollsSuccess(ctx, n.name)
126126
pollFailures = 0
127127
}

multinode/node_lifecycle_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func TestUnit_NodeLifecycle_aliveLoop(t *testing.T) {
381381
defer func() { assert.NoError(t, node.close()) }()
382382
node.declareAlive()
383383
tests.AssertEventually(t, func() bool {
384-
metric, err := metrics.PromPoolRPCNodeHighestFinalizedBlock.GetMetricWithLabelValues(big.NewInt(1).String(), name)
384+
metric, err := metrics.PromPoolRPCNodeHighestFinalizedBlock.GetMetricWithLabelValues("test-network", big.NewInt(1).String(), name)
385385
require.NoError(t, err)
386386
var m = &prom.Metric{}
387387
require.NoError(t, metric.Write(m))
@@ -466,7 +466,7 @@ func TestUnit_NodeLifecycle_aliveLoop(t *testing.T) {
466466
writeHeads(t, ch, head{BlockNumber: expectedBlock - 1}, head{BlockNumber: expectedBlock}, head{BlockNumber: expectedBlock - 1})
467467
}()
468468
tests.AssertEventually(t, func() bool {
469-
metric, err := promPoolRPCNodeHighestFinalizedBlock.GetMetricWithLabelValues(big.NewInt(1).String(), name)
469+
metric, err := metrics.PromPoolRPCNodeHighestFinalizedBlock.GetMetricWithLabelValues("test-network", big.NewInt(1).String(), name)
470470
require.NoError(t, err)
471471
var m = &prom.Metric{}
472472
require.NoError(t, metric.Write(m))

multinode/node_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package multinode
22

33
import (
4+
"github.com/smartcontractkit/chainlink-framework/metrics"
5+
"github.com/stretchr/testify/require"
46
"net/url"
57
"testing"
68
"time"
@@ -103,7 +105,10 @@ func newTestNode(t *testing.T, opts testNodeOpts) testNode {
103105
opts.id = 42
104106
}
105107

106-
nodeI := NewNode[ID, Head, RPCClient[ID, Head]](opts.config, opts.chainConfig, opts.lggr, makeMockNodeMetrics(t),
108+
nodeMetrics, err := metrics.NewGenericMultiNodeMetrics("test-network", "1")
109+
require.NoError(t, err)
110+
111+
nodeI := NewNode[ID, Head, RPCClient[ID, Head]](opts.config, opts.chainConfig, opts.lggr, nodeMetrics,
107112
opts.wsuri, opts.httpuri, opts.name, opts.id, opts.chainID, opts.nodeOrder, opts.rpc, opts.chainFamily)
108113

109114
return testNode{
@@ -123,5 +128,12 @@ func makeMockNodeMetrics(t *testing.T) *mockNodeMetrics {
123128
mockMetrics.On("IncrementNodeTransitionsToInvalidChainID", mock.Anything, mock.Anything).Maybe()
124129
mockMetrics.On("IncrementNodeTransitionsToUnusable", mock.Anything, mock.Anything).Maybe()
125130
mockMetrics.On("IncrementNodeTransitionsToSyncing", mock.Anything, mock.Anything).Maybe()
131+
mockMetrics.On("SetHighestSeenBlock", mock.Anything, mock.Anything, mock.Anything).Maybe()
132+
mockMetrics.On("SetHighestFinalizedBlock", mock.Anything, mock.Anything, mock.Anything).Maybe()
133+
mockMetrics.On("IncrementSeenBlocks", mock.Anything, mock.Anything).Maybe()
134+
mockMetrics.On("IncrementPolls", mock.Anything, mock.Anything).Maybe()
135+
mockMetrics.On("IncrementPollsFailed", mock.Anything, mock.Anything).Maybe()
136+
mockMetrics.On("IncrementPollsSuccess", mock.Anything, mock.Anything).Maybe()
137+
mockMetrics.On("RecordNodeClientVersion", mock.Anything, mock.Anything, mock.Anything).Maybe()
126138
return mockMetrics
127139
}

0 commit comments

Comments
 (0)