Tests fix.

This commit is contained in:
l.subbotin 2024-10-23 22:45:29 +02:00
parent 6eaeb91be2
commit 199b6694d5
No known key found for this signature in database
GPG Key ID: EBEF03B4E1049D77
2 changed files with 56 additions and 4 deletions

View File

@ -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 =====:
*/

View File

@ -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)