Skip to content

Commit

Permalink
stabilize flaky helpers in testproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyzags committed Jan 21, 2025
1 parent 987b2ec commit ea1fdf6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
29 changes: 18 additions & 11 deletions pkg/relayer/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ func (t *RelayProxyPingAllSuite) SetupSuite() {
appPrivateKey := secp256k1.GenPrivKey()
t.defaultRelayMinerServerAddress = "127.0.0.1:8245"
t.defaultServiceName = "defaultService"

t.supplierEndpoints = map[string][]*sharedtypes.SupplierEndpoint{
t.defaultServiceName: {
{
Expand Down Expand Up @@ -641,7 +640,9 @@ func (t *RelayProxyPingAllSuite) TestOKPingAllWithSingleRelayServer() {

}()

time.Sleep(time.Millisecond)
// waiting for relayer proxy to start
// and perform ping request.
time.Sleep(100 * time.Millisecond)

err = rp.PingAll(ctx)
require.NoError(t.T(), err)
Expand Down Expand Up @@ -716,7 +717,9 @@ func (t *RelayProxyPingAllSuite) TestOKPingAllWithMultipleRelayServers() {
}
}()

time.Sleep(time.Millisecond)
// waiting for relayer proxy to start
// and perform ping request.
time.Sleep(100 * time.Millisecond)

err = rp.PingAll(ctx)
require.NoError(t.T(), err)
Expand Down Expand Up @@ -804,7 +807,7 @@ func (t *RelayProxyPingAllSuite) TestNOKPingAllWithPartialFailureAfterStartup()
supplierEndpoints := map[string][]*sharedtypes.SupplierEndpoint{
failingServiceName: {
{
Url: "http://failingservice:8647",
Url: "http://failingservice:8648",
RpcType: sharedtypes.RPCType_JSON_RPC,
},
},
Expand All @@ -821,7 +824,7 @@ func (t *RelayProxyPingAllSuite) TestNOKPingAllWithPartialFailureAfterStartup()
ServiceConfig: &config.RelayMinerSupplierServiceConfig{
BackendUrl: &url.URL{
Scheme: "http",
Host: "127.0.0.1:8647",
Host: "127.0.0.1:8648",
Path: "/",
},
},
Expand Down Expand Up @@ -859,7 +862,9 @@ func (t *RelayProxyPingAllSuite) TestNOKPingAllWithPartialFailureAfterStartup()
}
}()

time.Sleep(time.Millisecond)
// waiting for relayer proxy to start
// and perform ping request.
time.Sleep(100 * time.Millisecond)

err = test.ShutdownServiceID(failingServiceName)
require.NoError(t.T(), err)
Expand Down Expand Up @@ -896,13 +901,13 @@ func (t *RelayProxyPingAllSuite) TestOKPingAllDifferentEndpoint() {
supplierEndpoints := map[string][]*sharedtypes.SupplierEndpoint{
relayminerZoneServiceName: {
{
Url: "http://exampleservice.org:8648",
Url: "http://exampleservice.org:8649",
RpcType: sharedtypes.RPCType_JSON_RPC,
},
},
relayminerIPV6ServiceName: {
{
Url: "http://ipv6service:8649",
Url: "http://ipv6service:8650",
RpcType: sharedtypes.RPCType_JSON_RPC,
},
},
Expand All @@ -919,7 +924,7 @@ func (t *RelayProxyPingAllSuite) TestOKPingAllDifferentEndpoint() {
ServiceConfig: &config.RelayMinerSupplierServiceConfig{
BackendUrl: &url.URL{
Scheme: "http",
Host: "exampleservice.org:8648",
Host: "exampleservice.org:8649",
Path: "/",
},
},
Expand All @@ -939,7 +944,7 @@ func (t *RelayProxyPingAllSuite) TestOKPingAllDifferentEndpoint() {
ServiceConfig: &config.RelayMinerSupplierServiceConfig{
BackendUrl: &url.URL{
Scheme: "http",
Host: "[::1]:8649",
Host: "[::1]:8650",
Path: "/",
},
},
Expand Down Expand Up @@ -977,7 +982,9 @@ func (t *RelayProxyPingAllSuite) TestOKPingAllDifferentEndpoint() {
}
}()

time.Sleep(time.Millisecond)
// waiting for relayer proxy to start
// and perform ping request.
time.Sleep(100 * time.Millisecond)

err = rp.PingAll(ctx)
require.NoError(t.T(), err)
Expand Down
15 changes: 10 additions & 5 deletions testutil/testproxy/relayerproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -183,13 +184,17 @@ $ go test -v -count=1 -run TestRelayerProxy ./pkg/relayer/...`)
}
for _, serviceConfig := range servicesConfigMap {
for serviceId, supplierConfig := range serviceConfig.SupplierConfigsMap {
server := &http.Server{Addr: supplierConfig.ServiceConfig.BackendUrl.Host}
server.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
sendJSONRPCResponse(test.t, w)
})
listener, err := net.Listen("tcp", supplierConfig.ServiceConfig.BackendUrl.Host)
require.NoError(test.t, err)

server := &http.Server{
Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
sendJSONRPCResponse(test.t, w)
}),
}

go func() {
err := server.ListenAndServe()
err := server.Serve(listener)
if err != nil && !errors.Is(err, http.ErrServerClosed) {
require.NoError(test.t, err)
}
Expand Down

0 comments on commit ea1fdf6

Please sign in to comment.