forked from skip-mev/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics_test.go
66 lines (59 loc) · 1.88 KB
/
metrics_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package oracle_test
import (
"context"
"errors"
"math/big"
"time"
"github.com/skip-mev/slinky/oracle"
"github.com/skip-mev/slinky/oracle/config"
metricmocks "github.com/skip-mev/slinky/oracle/metrics/mocks"
"github.com/skip-mev/slinky/oracle/types"
mathtestutils "github.com/skip-mev/slinky/pkg/math/testutils"
"github.com/skip-mev/slinky/providers/base/testutils"
oraclefactory "github.com/skip-mev/slinky/providers/factories/oracle"
)
func (s *OracleTestSuite) TestMetrics() {
cfg := config.OracleConfig{
UpdateInterval: 1 * time.Second,
MaxPriceAge: 1 * time.Minute,
Providers: nil,
Metrics: oracleCfg.Metrics,
Host: oracleCfg.Host,
Port: oracleCfg.Port,
}
provider := testutils.CreateAPIProviderWithGetResponses[types.ProviderTicker, *big.Float](
s.T(),
s.logger,
providerCfg1,
s.currencyPairs,
nil,
200*time.Millisecond,
)
ctx, cancel := context.WithTimeout(context.Background(), 10*cfg.UpdateInterval)
defer cancel()
metrics := metricmocks.NewMetrics(s.T())
testOracle, err := oracle.New(
cfg,
mathtestutils.NewMedianAggregator(),
oracle.WithLogger(s.logger),
oracle.WithPriceProviders(provider),
oracle.WithPriceAPIQueryHandlerFactory(oraclefactory.APIQueryHandlerFactory),
oracle.WithPriceWebSocketQueryHandlerFactory(oraclefactory.WebSocketQueryHandlerFactory),
oracle.WithMarketMap(s.marketmap),
oracle.WithMetrics(metrics),
)
s.Require().NoError(err)
go func() {
err := testOracle.Start(ctx)
if err != nil {
if !errors.Is(err, context.Canceled) && !errors.Is(err, context.DeadlineExceeded) {
s.T().Errorf("Start() should have returned context.Canceled error. Got: %v", err)
}
}
}()
metrics.On("SetSlinkyBuildInfo").Return()
metrics.On("AddTick").Return()
time.Sleep(2 * cfg.UpdateInterval)
testOracle.Stop() // block on the oracle actually closing
metrics.AssertExpectations(s.T())
}