Skip to content

Commit

Permalink
app/eth2wrap: improve flapping test (#1980)
Browse files Browse the repository at this point in the history
Fix flapping eth2wrap test by not relying on timeout but rather returning a 500. This allows increasing the timeout since CI/CD server is overloaded and often takes longer than 10ms to connect to valid server.

category: test
ticket: none
  • Loading branch information
corverroos authored Mar 30, 2023
1 parent 2b0c25f commit b97c31c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/eth2wrap/eth2wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewMultiHTTP(ctx context.Context, timeout time.Duration, addresses ...strin
eth2http.WithTimeout(timeout),
)
if err != nil {
return nil, wrapError(ctx, err, "new eth2 client")
return nil, wrapError(ctx, err, "new eth2 client", z.Str("address", address))
}
eth2Http, ok := eth2Svc.(*eth2http.Service)
if !ok {
Expand Down Expand Up @@ -281,7 +281,7 @@ func incError(endpoint string) {
}

// wrapError returns the error as a wrapped structured error.
func wrapError(ctx context.Context, err error, label string) error {
func wrapError(ctx context.Context, err error, label string, fields ...z.Field) error {
// Decompose go-eth2-client http errors
if e2err := new(eth2http.Error); errors.As(err, e2err) {
err = errors.New("nok http response",
Expand Down Expand Up @@ -317,7 +317,7 @@ func wrapError(ctx context.Context, err error, label string) error {
err = errors.Wrap(nerr.Err, msg, z.Any("address", nerr.Addr))
}

return errors.Wrap(err, "beacon api "+label, z.Str("label", label))
return errors.Wrap(err, "beacon api "+label, append(fields, z.Str("label", label))...)
}

// newBestSelector returns a new bestSelector.
Expand Down
14 changes: 10 additions & 4 deletions app/eth2wrap/eth2wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,26 @@ func TestBlockAttestations(t *testing.T) {
}

func TestOneDown(t *testing.T) {
// Start an erroring server.
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
}))
defer srv.Close()

ctx := context.Background()
bmock, err := beaconmock.New()
require.NoError(t, err)

addresses := []string{
"http://222.222.222.222:22222", // Invalid
bmock.Address(), // Valid
srv.URL, // Invalid
bmock.Address(), // Valid
}

eth2Cl, err := eth2wrap.NewMultiHTTP(ctx, time.Millisecond*10, addresses...)
eth2Cl, err := eth2wrap.NewMultiHTTP(ctx, time.Second, addresses...)
require.NoError(t, err)

_, err = eth2Cl.SlotDuration(ctx)
require.NoError(t, err)
testutil.RequireNoError(t, err)

require.Equal(t, bmock.Address(), eth2Cl.Address())
}
Expand Down

0 comments on commit b97c31c

Please sign in to comment.