@@ -1314,7 +1314,7 @@ func TestNativeHistogramExemplar(t *testing.T) {
1314
1314
{
1315
1315
name : "remove exemplar with oldest timestamp, the removed index is smaller than inserted index" ,
1316
1316
addFunc : func (h * histogram ) {
1317
- time . Sleep ( 10 * time .Second )
1317
+ h . now = func () time. Time { return time .Now (). Add ( time . Second * 11 ) }
1318
1318
h .ObserveWithExemplar (6 , Labels {"id" : "1" })
1319
1319
},
1320
1320
expectedValues : []float64 {0 , 4 , 6 },
@@ -1324,14 +1324,7 @@ func TestNativeHistogramExemplar(t *testing.T) {
1324
1324
for _ , tc := range tcs {
1325
1325
t .Run (tc .name , func (t * testing.T ) {
1326
1326
tc .addFunc (h )
1327
- if len (h .nativeExemplars .exemplars ) != len (tc .expectedValues ) {
1328
- t .Errorf ("the count of exemplars is not %d" , len (tc .expectedValues ))
1329
- }
1330
- for i , e := range h .nativeExemplars .exemplars {
1331
- if e .GetValue () != tc .expectedValues [i ] {
1332
- t .Errorf ("the %dth exemplar value %v is not as expected: %v" , i , e .GetValue (), tc .expectedValues [i ])
1333
- }
1334
- }
1327
+ compareNativeExemplarValues (t , h .nativeExemplars .exemplars , tc .expectedValues )
1335
1328
})
1336
1329
}
1337
1330
@@ -1385,14 +1378,7 @@ func TestNativeHistogramExemplar(t *testing.T) {
1385
1378
for _ , tc := range tcs {
1386
1379
t .Run (tc .name , func (t * testing.T ) {
1387
1380
tc .addFunc (h )
1388
- if len (h .nativeExemplars .exemplars ) != len (tc .expectedValues ) {
1389
- t .Errorf ("the count of exemplars is not %d" , len (tc .expectedValues ))
1390
- }
1391
- for i , e := range h .nativeExemplars .exemplars {
1392
- if e .GetValue () != tc .expectedValues [i ] {
1393
- t .Errorf ("the %dth exemplar value %v is not as expected: %v" , i , e .GetValue (), tc .expectedValues [i ])
1394
- }
1395
- }
1381
+ compareNativeExemplarValues (t , h .nativeExemplars .exemplars , tc .expectedValues )
1396
1382
})
1397
1383
}
1398
1384
@@ -1425,14 +1411,18 @@ func TestNativeHistogramExemplar(t *testing.T) {
1425
1411
for _ , tc := range tcs {
1426
1412
t .Run (tc .name , func (t * testing.T ) {
1427
1413
tc .addFunc (h )
1428
- if len (h .nativeExemplars .exemplars ) != len (tc .expectedValues ) {
1429
- t .Errorf ("the count of exemplars is not %d" , len (tc .expectedValues ))
1430
- }
1431
- for i , e := range h .nativeExemplars .exemplars {
1432
- if e .GetValue () != tc .expectedValues [i ] {
1433
- t .Errorf ("the %dth exemplar value %v is not as expected: %v" , i , e .GetValue (), tc .expectedValues [i ])
1434
- }
1435
- }
1414
+ compareNativeExemplarValues (t , h .nativeExemplars .exemplars , tc .expectedValues )
1436
1415
})
1437
1416
}
1438
1417
}
1418
+
1419
+ func compareNativeExemplarValues (t * testing.T , exps []* dto.Exemplar , values []float64 ) {
1420
+ if len (exps ) != len (values ) {
1421
+ t .Errorf ("the count of exemplars is not %d" , len (values ))
1422
+ }
1423
+ for i , e := range exps {
1424
+ if e .GetValue () != values [i ] {
1425
+ t .Errorf ("the %dth exemplar value %v is not as expected: %v" , i , e .GetValue (), values [i ])
1426
+ }
1427
+ }
1428
+ }
0 commit comments