Skip to content

Commit

Permalink
Merge pull request #174 from wetcod/http-test3
Browse files Browse the repository at this point in the history
test: don't use foo-bar.net in TestHTTPClientMakeHTTPDialer
  • Loading branch information
wetcod authored Feb 4, 2021
2 parents a01efd2 + 02645eb commit d417f1d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:
for pkg in $(go list github.com/tendermint/tendermint/... | circleci tests split --split-by=timings); do
id=$(basename "$pkg")
prefix=$(basename ${pkg%$id})
go test -v -timeout 5m -mod=readonly -race -coverprofile=/tmp/workspace/profiles/$prefix-$id.out -covermode=atomic "$pkg" | tee "/tmp/logs/$id-$RANDOM.log"
go test -v -timeout 10m -mod=readonly -race -coverprofile=/tmp/workspace/profiles/$prefix-$id.out -covermode=atomic "$pkg" | tee "/tmp/logs/$id-$RANDOM.log"
done
- persist_to_workspace:
root: /tmp/workspace
Expand Down
23 changes: 18 additions & 5 deletions rpc/jsonrpc/client/http_json_client_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
package client

import (
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/require"
)

func TestHTTPClientMakeHTTPDialer(t *testing.T) {
remote := []string{"https://foo-bar.com:80", "http://foo-bar.net:80", "https://user:pass@foo-bar.net:80"}
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("Hi!\n"))
})
ts := httptest.NewServer(handler)
defer ts.Close()

for _, f := range remote {
u, err := newParsedURL(f)
tsTLS := httptest.NewTLSServer(handler)
defer tsTLS.Close()
// This silences a TLS handshake error, caused by the dialer just immediately
// disconnecting, which we can just ignore.
tsTLS.Config.ErrorLog = log.New(ioutil.Discard, "", 0)

for _, testURL := range []string{ts.URL, tsTLS.URL} {
u, err := newParsedURL(testURL)
require.NoError(t, err)
dialFn, err := makeHTTPDialer(f)
dialFn, err := makeHTTPDialer(testURL)
require.Nil(t, err)

addr, err := dialFn(u.Scheme, u.GetHostWithPath())
require.NoError(t, err)
require.NotNil(t, addr)
}

}

0 comments on commit d417f1d

Please sign in to comment.