@@ -13,6 +13,7 @@ import (
13
13
"time"
14
14
15
15
"github.com/prometheus/client_golang/prometheus"
16
+ "github.com/prometheus/client_golang/prometheus/testutil"
16
17
"github.com/stretchr/testify/require"
17
18
"go.uber.org/mock/gomock"
18
19
@@ -2530,3 +2531,43 @@ func TestLocalParse(t *testing.T) {
2530
2531
})
2531
2532
}
2532
2533
}
2534
+
2535
+ func TestTimestampMetrics (t * testing.T ) {
2536
+ ctx := context .Background ()
2537
+
2538
+ coreVM , _ , proVM , _ := initTestProposerVM (t , time .Unix (0 , 0 ), mockable .MaxTime , 0 )
2539
+ defer func () {
2540
+ require .NoError (t , proVM .Shutdown (ctx ))
2541
+ }()
2542
+
2543
+ innerBlock := snowmantest .BuildChild (snowmantest .Genesis )
2544
+
2545
+ outerTime := time .Unix (314159 , 0 )
2546
+ innerTime := time .Unix (142857 , 0 )
2547
+ proVM .Clock .Set (outerTime )
2548
+ innerBlock .TimestampV = innerTime
2549
+
2550
+ coreVM .BuildBlockF = func (context.Context ) (snowman.Block , error ) {
2551
+ return innerBlock , nil
2552
+ }
2553
+ outerBlock , err := proVM .BuildBlock (ctx )
2554
+ require .NoError (t , err )
2555
+ require .IsType (t , & postForkBlock {}, outerBlock )
2556
+ require .NoError (t , outerBlock .Accept (ctx ))
2557
+
2558
+ gaugeVec := proVM .lastAcceptedTimestampGaugeVec
2559
+ tests := []struct {
2560
+ blockType string
2561
+ want time.Time
2562
+ }{
2563
+ {innerBlockTypeMetricLabel , innerTime },
2564
+ {outerBlockTypeMetricLabel , outerTime },
2565
+ }
2566
+ for _ , tt := range tests {
2567
+ t .Run (tt .blockType , func (t * testing.T ) {
2568
+ gauge , err := gaugeVec .GetMetricWithLabelValues (tt .blockType )
2569
+ require .NoError (t , err )
2570
+ require .Equal (t , float64 (tt .want .Unix ()), testutil .ToFloat64 (gauge ))
2571
+ })
2572
+ }
2573
+ }
0 commit comments