Skip to content

Commit

Permalink
fix tests/nits
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew7234 committed Jan 12, 2024
1 parent 09f6991 commit d83c474
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
5 changes: 2 additions & 3 deletions analyzer/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,9 @@ func (b *blockBasedAnalyzer) ensureSlowSyncPrerequisites(ctx context.Context) (o
// between the analyzer's highest processed block and the current block height
// on-chain (fetched by the node-stats analyzer).
// Note that the true count may be higher during fast-sync.
func (b *blockBasedAnalyzer) sendQueueLengthMetric(ctx context.Context, queueLength uint64) error {
func (b *blockBasedAnalyzer) sendQueueLengthMetric(queueLength uint64) {
// For block-based analyzers, the analyzer name is identical to the layer name.
b.metrics.QueueLength(b.analyzerName).Set(float64(queueLength))
return nil
}

// Returns the chain height of the layer this analyzer is processing.
Expand Down Expand Up @@ -419,7 +418,7 @@ func (b *blockBasedAnalyzer) Start(ctx context.Context) {
}
// If we successfully fetched the node height earlier, update the estimated queue length.
if nodeHeight != -1 {
b.sendQueueLengthMetric(ctx, uint64(nodeHeight)-height)
b.sendQueueLengthMetric(uint64(nodeHeight) - height)
}
cancel()
backoff.Success()
Expand Down
16 changes: 8 additions & 8 deletions analyzer/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func setupAnalyzer(t *testing.T, testDb *postgres.Client, p *mockProcessor, cfg
p.isFastSync = (mode == analyzer.FastSyncMode)

// Initialize the block analyzer.
logger, err := log.NewLogger(fmt.Sprintf("test-analyzer-%s", p.name), os.Stdout, log.FmtJSON, log.LevelInfo)
logger, err := log.NewLogger(fmt.Sprintf("test_analyzer-%s", p.name), os.Stdout, log.FmtJSON, log.LevelInfo)
require.NoError(t, err, "log.NewLogger")
var blockRange config.BlockRange
switch mode {
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestFastSyncBlockAnalyzer(t *testing.T) {
ctx := context.Background()

db := setupDB(t)
p := &mockProcessor{name: "test-analyzer", storage: db}
p := &mockProcessor{name: "test_analyzer", storage: db}
analyzer := setupAnalyzer(t, db, p, testBlockBasedConfig, analyzer.SlowSyncMode)

// Run the analyzer and ensure all blocks are processed.
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestMultipleFastSyncBlockAnalyzers(t *testing.T) {
ps := []*mockProcessor{}
as := []analyzer.Analyzer{}
for i := 0; i < numAnalyzers; i++ {
p := &mockProcessor{name: "test-analyzer", storage: db}
p := &mockProcessor{name: "test_analyzer", storage: db}
analyzer := setupAnalyzer(t, db, p, testFastSyncBlockBasedConfig, analyzer.FastSyncMode)
ps = append(ps, p)
as = append(as, analyzer)
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestFailingFastSyncBlockAnalyzers(t *testing.T) {
return fmt.Errorf("failing analyzer")
}
}
p := &mockProcessor{name: "test-analyzer", storage: db, fail: fail}
p := &mockProcessor{name: "test_analyzer", storage: db, fail: fail}
analyzer := setupAnalyzer(t, db, p, testFastSyncBlockBasedConfig, analyzer.FastSyncMode)
ps = append(ps, p)
as = append(as, analyzer)
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestDistinctFastSyncBlockAnalyzers(t *testing.T) {
ps := []*mockProcessor{}
as := []analyzer.Analyzer{}
for i := 0; i < numAnalyzers; i++ {
p := &mockProcessor{name: fmt.Sprintf("test-analyzer-%d", i), storage: db}
p := &mockProcessor{name: fmt.Sprintf("test_analyzer_%d", i), storage: db}
analyzer := setupAnalyzer(t, db, p, testFastSyncBlockBasedConfig, analyzer.FastSyncMode)
ps = append(ps, p)
as = append(as, analyzer)
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestSlowSyncBlockAnalyzer(t *testing.T) {
ctx := context.Background()

db := setupDB(t)
p := &mockProcessor{name: "test-analyzer", storage: db}
p := &mockProcessor{name: "test_analyzer", storage: db}
analyzer := setupAnalyzer(t, db, p, testBlockBasedConfig, analyzer.SlowSyncMode)

// Run the analyzer and ensure all blocks are processed.
Expand Down Expand Up @@ -351,7 +351,7 @@ func TestFailingSlowSyncBlockAnalyzer(t *testing.T) {
ctx := context.Background()

db := setupDB(t)
p := &mockProcessor{name: "test-analyzer", storage: db, fail: func(height uint64) error {
p := &mockProcessor{name: "test_analyzer", storage: db, fail: func(height uint64) error {
// Fail ~5% of the time.
if rand.Float64() > 0.95 { // /nolint:gosec // G404: Use of weak random number generator (math/rand instead of crypto/rand).
return fmt.Errorf("failed by chance")
Expand Down Expand Up @@ -394,7 +394,7 @@ func TestDistinctSlowSyncBlockAnalyzers(t *testing.T) {
ps := []*mockProcessor{}
as := []analyzer.Analyzer{}
for i := 0; i < numAnalyzers; i++ {
p := &mockProcessor{name: fmt.Sprintf("test-analyzer-%d", i), storage: db}
p := &mockProcessor{name: fmt.Sprintf("test_analyzer_%d", i), storage: db}
analyzer := setupAnalyzer(t, db, p, testBlockBasedConfig, analyzer.SlowSyncMode)
ps = append(ps, p)
as = append(as, analyzer)
Expand Down

0 comments on commit d83c474

Please sign in to comment.