Skip to content

Commit

Permalink
fix(price-feeder): BinanceUS too many requests socket close error (#1769
Browse files Browse the repository at this point in the history
)

remove integration test fixture and parse config instead
  • Loading branch information
zarazan authored Feb 2, 2023
1 parent 00c708d commit b1518c7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 101 deletions.
2 changes: 1 addition & 1 deletion price-feeder/cmd/price-feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func priceFeederCmdHandler(cmd *cobra.Command, args []string) error {
oracle := oracle.New(
logger,
oracleClient,
cfg.CurrencyPairs,
cfg.ProviderPairs(),
providerTimeout,
deviations,
endpoints,
Expand Down
15 changes: 15 additions & 0 deletions price-feeder/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/rs/zerolog"
"github.com/spf13/viper"
"github.com/umee-network/umee/price-feeder/v2/oracle/provider"
"github.com/umee-network/umee/price-feeder/v2/oracle/types"
)

const (
Expand Down Expand Up @@ -156,6 +157,20 @@ func (c Config) Validate() error {
return validate.Struct(c)
}

func (c Config) ProviderPairs() map[provider.Name][]types.CurrencyPair {
providerPairs := make(map[provider.Name][]types.CurrencyPair)

for _, pair := range c.CurrencyPairs {
for _, provider := range pair.Providers {
providerPairs[provider] = append(providerPairs[provider], types.CurrencyPair{
Base: pair.Base,
Quote: pair.Quote,
})
}
}
return providerPairs
}

// ParseConfig attempts to read and parse configuration from the given file path.
// An error is returned if reading or parsing the config fails.
func ParseConfig(configPath string) (Config, error) {
Expand Down
14 changes: 1 addition & 13 deletions price-feeder/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"google.golang.org/grpc/credentials/insecure"

"github.com/cosmos/cosmos-sdk/telemetry"
"github.com/umee-network/umee/price-feeder/v2/config"
"github.com/umee-network/umee/price-feeder/v2/oracle/client"
"github.com/umee-network/umee/price-feeder/v2/oracle/provider"
"github.com/umee-network/umee/price-feeder/v2/oracle/types"
Expand Down Expand Up @@ -78,22 +77,11 @@ type Oracle struct {
func New(
logger zerolog.Logger,
oc client.OracleClient,
currencyPairs []config.CurrencyPair,
providerPairs map[provider.Name][]types.CurrencyPair,
providerTimeout time.Duration,
deviations map[string]sdk.Dec,
endpoints map[provider.Name]provider.Endpoint,
) *Oracle {
providerPairs := make(map[provider.Name][]types.CurrencyPair)

for _, pair := range currencyPairs {
for _, provider := range pair.Providers {
providerPairs[provider] = append(providerPairs[provider], types.CurrencyPair{
Base: pair.Base,
Quote: pair.Quote,
})
}
}

return &Oracle{
logger: logger.With().Str("module", "oracle").Logger(),
closer: pfsync.NewCloser(),
Expand Down
48 changes: 26 additions & 22 deletions price-feeder/oracle/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/umee-network/umee/price-feeder/v2/config"
"github.com/umee-network/umee/price-feeder/v2/oracle/client"
"github.com/umee-network/umee/price-feeder/v2/oracle/provider"
"github.com/umee-network/umee/price-feeder/v2/oracle/types"
Expand Down Expand Up @@ -78,31 +77,36 @@ func (ots *OracleTestSuite) SetupSuite() {
ots.oracle = New(
zerolog.Nop(),
client.OracleClient{},
[]config.CurrencyPair{
{
Base: "UMEE",
Quote: "USDT",
Providers: []provider.Name{provider.ProviderBinance},
map[provider.Name][]types.CurrencyPair{
provider.ProviderBinance: {
{
Base: "UMEE",
Quote: "USDT",
},
},
{
Base: "UMEE",
Quote: "USDC",
Providers: []provider.Name{provider.ProviderKraken},
provider.ProviderKraken: {
{
Base: "UMEE",
Quote: "USDC",
},
},
{
Base: "XBT",
Quote: "USDT",
Providers: []provider.Name{provider.ProviderOsmosis},
provider.ProviderOsmosis: {
{
Base: "XBT",
Quote: "USDT",
},
},
{
Base: "USDC",
Quote: "USD",
Providers: []provider.Name{provider.ProviderHuobi},
provider.ProviderHuobi: {
{
Base: "USDC",
Quote: "USD",
},
},
{
Base: "USDT",
Quote: "USD",
Providers: []provider.Name{provider.ProviderCoinbase},
provider.ProviderCoinbase: {
{
Base: "USDT",
Quote: "USD",
},
},
},
time.Millisecond*100,
Expand Down
59 changes: 0 additions & 59 deletions price-feeder/tests/integration/fixtures.go

This file was deleted.

16 changes: 10 additions & 6 deletions price-feeder/tests/integration/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/umee-network/umee/price-feeder/v2/config"
"github.com/umee-network/umee/price-feeder/v2/oracle"
"github.com/umee-network/umee/price-feeder/v2/oracle/provider"
"github.com/umee-network/umee/price-feeder/v2/oracle/types"
Expand All @@ -34,15 +35,18 @@ func (s *IntegrationTestSuite) TestWebsocketProviders() {
s.T().Skip("skipping integration test in short mode")
}

testCases := ProviderAndCurrencyPairsFixture
for _, testCase := range testCases {
tc := testCase
s.T().Run(string(tc.provider), func(t *testing.T) {
cfg, err := config.ParseConfig("../../price-feeder.example.toml")
require.NoError(s.T(), err)

for key, pairs := range cfg.ProviderPairs() {
providerName := key
currencyPairs := pairs
s.T().Run(string(providerName), func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
pvd, _ := oracle.NewProvider(ctx, tc.provider, getLogger(), provider.Endpoint{}, tc.currencyPairs...)
pvd, _ := oracle.NewProvider(ctx, providerName, getLogger(), provider.Endpoint{}, currencyPairs...)
time.Sleep(30 * time.Second) // wait for provider to connect and receive some prices
checkForPrices(t, pvd, tc.currencyPairs)
checkForPrices(t, pvd, currencyPairs)
cancel()
})
}
Expand Down

0 comments on commit b1518c7

Please sign in to comment.