From 4f5faa5f31a0784a64e49e345890ba337a394e4b Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Wed, 18 Sep 2019 13:42:28 +0200 Subject: [PATCH] address pr comments --- p2p/switch_test.go | 6 +++++- rpc/core/consensus.go | 22 +++------------------- rpc/lib/client/ws_client.go | 1 + rpc/lib/server/handlers_test.go | 1 + 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/p2p/switch_test.go b/p2p/switch_test.go index 0879acc2d..ac964cba9 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -352,7 +352,11 @@ func TestSwitchStopPeerForError(t *testing.T) { defer s.Close() scrapeMetrics := func() string { - resp, _ := http.Get(s.URL) + resp, err := http.Get(s.URL) + if err != nil { + t.Errorf("error on GET request: %v", err) + } + defer resp.Body.Close() buf, _ := ioutil.ReadAll(resp.Body) return string(buf) } diff --git a/rpc/core/consensus.go b/rpc/core/consensus.go index 6779d6d2b..219c3f1e9 100644 --- a/rpc/core/consensus.go +++ b/rpc/core/consensus.go @@ -70,13 +70,6 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ct if err != nil { return nil, err } - // page & perPage === 0 then all validators are returned, no pagination - if page == 0 && perPage == 0 { - return &ctypes.ResultValidators{ - BlockHeight: height, - Validators: validators.Validators, - }, nil - } totalCount := len(validators.Validators) perPage = validatePerPage(perPage) @@ -84,23 +77,14 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ct if err != nil { return nil, err } - skipCount := validateSkipCount(page, perPage) - apiResults := make([]*types.Validator, cmn.MinInt(perPage, totalCount-skipCount)) - for i := 0; i < len(apiResults); i++ { - v := validators.Validators[skipCount+i] + skipCount := validateSkipCount(page, perPage) - apiResults[i] = &types.Validator{ - Address: v.Address, - PubKey: v.PubKey, - VotingPower: v.VotingPower, - ProposerPriority: v.ProposerPriority, - } - } + v := validators.Validators[skipCount : skipCount+cmn.MinInt(perPage, totalCount-skipCount)] return &ctypes.ResultValidators{ BlockHeight: height, - Validators: apiResults}, nil + Validators: v}, nil } // DumpConsensusState dumps consensus state. diff --git a/rpc/lib/client/ws_client.go b/rpc/lib/client/ws_client.go index 1779e9dbd..863b03d79 100644 --- a/rpc/lib/client/ws_client.go +++ b/rpc/lib/client/ws_client.go @@ -253,6 +253,7 @@ func (c *WSClient) dial() error { } rHeader := http.Header{} conn, _, err := dialer.Dial(c.protocol+"://"+c.Address+c.Endpoint, rHeader) + defer conn.Close() if err != nil { return err } diff --git a/rpc/lib/server/handlers_test.go b/rpc/lib/server/handlers_test.go index 9cded2953..cb178d307 100644 --- a/rpc/lib/server/handlers_test.go +++ b/rpc/lib/server/handlers_test.go @@ -70,6 +70,7 @@ func TestRPCParams(t *testing.T) { rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) res := rec.Result() + defer res.Body.Close() // Always expecting back a JSONRPCResponse assert.True(t, statusOK(res.StatusCode), "#%d: should always return 2XX", i) blob, err := ioutil.ReadAll(res.Body)