diff --git a/cmd/solana_exporter/exporter_test.go b/cmd/solana_exporter/exporter_test.go index 67ea6bc..39254bf 100644 --- a/cmd/solana_exporter/exporter_test.go +++ b/cmd/solana_exporter/exporter_test.go @@ -185,6 +185,30 @@ func (c *staticRPCClient) GetHealth(ctx context.Context) (*string, error) { return &health, nil } +//goland:noinspection GoUnusedParameter +func (c *staticRPCClient) GetIdentity(ctx context.Context) (*string, error) { + nodeIdentity := "aaa" + return &nodeIdentity, nil +} + +//goland:noinspection GoUnusedParameter +func (c *staticRPCClient) GetBlockHeight(ctx context.Context) (*int64, error) { + blockHeight := int64(1233) + return &blockHeight, nil +} + +//goland:noinspection GoUnusedParameter +func (c *staticRPCClient) GetFirstAvailableBlock(ctx context.Context) (*int64, error) { + firstAvailiableBlock := int64(33) + return &firstAvailiableBlock, nil +} + +//goland:noinspection GoUnusedParameter +func (c *staticRPCClient) GetMinimumLedgerSlot(ctx context.Context) (*int64, error) { + minimumLedgerSlot := int64(23) + return &minimumLedgerSlot, nil +} + /* ===== DYNAMIC CLIENT =====: */ @@ -386,6 +410,30 @@ func (c *dynamicRPCClient) GetHealth(ctx context.Context) (*string, error) { return &health, nil } +//goland:noinspection GoUnusedParameter +func (c *dynamicRPCClient) GetIdentity(ctx context.Context) (*string, error) { + nodeIdentity := "aaa" + return &nodeIdentity, nil +} + +//goland:noinspection GoUnusedParameter +func (c *dynamicRPCClient) GetBlockHeight(ctx context.Context) (*int64, error) { + blockHeight := int64(1233) + return &blockHeight, nil +} + +//goland:noinspection GoUnusedParameter +func (c *dynamicRPCClient) GetFirstAvailableBlock(ctx context.Context) (*int64, error) { + firstAvailiableBlock := int64(33) + return &firstAvailiableBlock, nil +} + +//goland:noinspection GoUnusedParameter +func (c *dynamicRPCClient) GetMinimumLedgerSlot(ctx context.Context) (*int64, error) { + minimumLedgerSlot := int64(23) + return &minimumLedgerSlot, nil +} + /* ===== OTHER TEST UTILITIES =====: */ diff --git a/cmd/solana_exporter/slots_test.go b/cmd/solana_exporter/slots_test.go index ca44114..19c633e 100644 --- a/cmd/solana_exporter/slots_test.go +++ b/cmd/solana_exporter/slots_test.go @@ -90,14 +90,16 @@ func assertSlotMetricsChangeCorrectly(t *testing.T, initial slotMetricValues, fi func TestSolanaCollector_WatchSlots_Static(t *testing.T) { client := staticRPCClient{} - collector := NewSolanaCollector(&client, 100*time.Millisecond, nil, identities, votekeys) + ctx, cancel := context.WithCancel(context.Background()) + nodeIdentity, _ := client.GetIdentity(ctx) + collector := NewSolanaCollector(&client, 100*time.Millisecond, nil, identities, votekeys, nodeIdentity) watcher := NewSlotWatcher(&client, identities, votekeys, false, false) // reset metrics before running tests: watcher.LeaderSlotsTotalMetric.Reset() watcher.LeaderSlotsByEpochMetric.Reset() prometheus.NewPedanticRegistry().MustRegister(collector) - ctx, cancel := context.WithCancel(context.Background()) + defer cancel() go watcher.WatchSlots(ctx, collector.slotPace) @@ -159,7 +161,9 @@ func TestSolanaCollector_WatchSlots_Static(t *testing.T) { func TestSolanaCollector_WatchSlots_Dynamic(t *testing.T) { // create clients: client := newDynamicRPCClient() - collector := NewSolanaCollector(client, 300*time.Millisecond, nil, identities, votekeys) + runCtx, runCancel := context.WithCancel(context.Background()) + nodeIdentity, _ := client.GetIdentity(runCtx) + collector := NewSolanaCollector(client, 300*time.Millisecond, nil, identities, votekeys, nodeIdentity) watcher := NewSlotWatcher(client, identities, votekeys, false, false) // reset metrics before running tests: watcher.LeaderSlotsTotalMetric.Reset() @@ -167,7 +171,7 @@ func TestSolanaCollector_WatchSlots_Dynamic(t *testing.T) { prometheus.NewPedanticRegistry().MustRegister(collector) // start client/collector and wait a bit: - runCtx, runCancel := context.WithCancel(context.Background()) + defer runCancel() go client.Run(runCtx) time.Sleep(time.Second)