Skip to content

Commit 9535af4

Browse files
committed
chore: adding some unit tests
1 parent 5935254 commit 9535af4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pkg/metrics/metrics_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package metrics
22

33
import (
44
"testing"
5+
"time"
56

67
"github.com/prometheus/client_golang/prometheus"
78
"github.com/stretchr/testify/require"
@@ -535,6 +536,33 @@ func TestMetrics_ComplexScenario(t *testing.T) {
535536
}
536537
}
537538

539+
func TestMetrics_RecordSubmissionDuration(t *testing.T) {
540+
reg := prometheus.NewRegistry()
541+
m := NewWithRegistry("test", reg)
542+
543+
// record submission durations
544+
m.RecordSubmissionDuration("chain1", "header", 5*time.Second)
545+
// overwrite submission duration
546+
m.RecordSubmissionDuration("chain1", "header", 6*time.Second)
547+
m.RecordSubmissionDuration("chain1", "data", 10*time.Second)
548+
m.RecordSubmissionDuration("chain2", "header", 3*time.Second)
549+
550+
// verify stored in memory
551+
require.Equal(t, 6*time.Second, m.lastSubmissionDurations["chain1:header"], "last submission duration should be present")
552+
require.Equal(t, 10*time.Second, m.lastSubmissionDurations["chain1:data"])
553+
require.Equal(t, 3*time.Second, m.lastSubmissionDurations["chain2:header"])
554+
}
555+
556+
func TestMetrics_RefreshSubmissionDuration_Empty(t *testing.T) {
557+
reg := prometheus.NewRegistry()
558+
m := NewWithRegistry("test", reg)
559+
560+
// call refresh without any recorded values - should not panic
561+
require.NotPanics(t, func() {
562+
m.RefreshSubmissionDuration()
563+
})
564+
}
565+
538566
// helper types for table tests
539567
type blockToRecord struct {
540568
chain string

0 commit comments

Comments
 (0)