Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
fix: rate limits exceeded
Browse files Browse the repository at this point in the history
Use private nodes when running tests and fallback to public nodes when
configuration is not provided.
  • Loading branch information
eitu5ami committed Dec 9, 2023
1 parent 0a1ebcf commit 84305b0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ linters-settings:
- github.com/stretchr/testify
- github.com/slok/go-http-metrics
- github.com/purini-to/zapmw
- github.com/caitlinelfring/go-env-default

issues:
max-same-issues: 0 # unlimited
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
github.com/Shopify/toxiproxy v2.1.4+incompatible
github.com/caitlinelfring/go-env-default v1.1.0
github.com/ethereum/go-ethereum v1.13.5
github.com/gorilla/mux v1.8.1
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWso
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/caitlinelfring/go-env-default v1.1.0 h1:bhDfXmUolvcIGfQCX8qevQX8wxC54NGz0aimoUnhvDM=
github.com/caitlinelfring/go-env-default v1.1.0/go.mod h1:tESXPr8zFPP/cRy3cwxrHBmjJIf2A1x/o4C9CET2rEk=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
5 changes: 3 additions & 2 deletions internal/proxy/healthchecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"github.com/caitlinelfring/go-env-default"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
Expand All @@ -22,7 +23,7 @@ func TestBasicHealthchecker(t *testing.T) {
defer cancel()

healtcheckConfig := RPCHealthcheckerConfig{
URL: "https://cloudflare-eth.com",
URL: env.GetDefault("RPC_GATEWAY_NODE_URL_1", "https://cloudflare-eth.com"),
Interval: 1 * time.Second,
Timeout: 2 * time.Second,
FailureThreshold: 1,
Expand All @@ -48,7 +49,7 @@ func TestBasicHealthchecker(t *testing.T) {

func TestGasLeftCall(t *testing.T) {
client := &http.Client{}
url := "https://cloudflare-eth.com"
url := env.GetDefault("RPC_GATEWAY_NODE_URL_1", "https://cloudflare-eth.com")

result, err := performGasLeftCall(context.TODO(), client, url)
assert.Nil(t, err)
Expand Down
7 changes: 4 additions & 3 deletions internal/proxy/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"github.com/caitlinelfring/go-env-default"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
)
Expand All @@ -18,15 +19,15 @@ func TestHealthcheckManager(t *testing.T) {
Name: "Primary",
Connection: TargetConfigConnection{
HTTP: TargetConnectionHTTP{
URL: "https://cloudflare-eth.com",
URL: env.GetDefault("RPC_GATEWAY_NODE_URL_1", "https://cloudflare-eth.com"),
},
},
},
{
Name: "StandBy",
Connection: TargetConfigConnection{
HTTP: TargetConnectionHTTP{
URL: "https://cloudflare-eth.com",
URL: env.GetDefault("RPC_GATEWAY_NODE_URL_1", "https://eth.public-rpc.com"),
},
},
},
Expand Down Expand Up @@ -65,7 +66,7 @@ func TestGetNextHealthyTargetIndexExcluding(t *testing.T) {
Name: "Primary",
Connection: TargetConfigConnection{
HTTP: TargetConnectionHTTP{
URL: "https://cloudflare-eth.com",
URL: env.GetDefault("RPC_GATEWAY_NODE_URL_1", "https://cloudflare-eth.com"),
},
},
},
Expand Down
5 changes: 3 additions & 2 deletions internal/rpcgateway/rpcgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

toxiproxy "github.com/Shopify/toxiproxy/client"
"github.com/caitlinelfring/go-env-default"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
Expand Down Expand Up @@ -77,7 +78,7 @@ func TestRpcGatewayFailover(t *testing.T) {
err := toxiClient.ResetState()
assert.Nil(t, err)

proxy, err := toxiClient.CreateProxy("cloudflare", "0.0.0.0:9991", ts.URL[7:])
proxy, err := toxiClient.CreateProxy("primary", "0.0.0.0:9991", ts.URL[7:])
assert.Nil(t, err)

_, err = proxy.AddToxic("latency_down", "latency", "downstream", 1.0, toxiproxy.Attributes{
Expand All @@ -92,7 +93,7 @@ func TestRpcGatewayFailover(t *testing.T) {

// config string
var tpl bytes.Buffer
tu := TestURL{"http://0.0.0.0:9991", "https://cloudflare-eth.com"}
tu := TestURL{"http://0.0.0.0:9991", env.GetDefault("RPC_GATEWAY_NODE_URL_1", "https://cloudflare-eth.com")}
tmpl, err := template.New("test").Parse(rpcGatewayConfig)
assert.Nil(t, err)

Expand Down

0 comments on commit 84305b0

Please sign in to comment.