|
|
@ -38,6 +38,8 @@ import ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func TestClientRequest(t *testing.T) { |
|
|
|
func TestClientRequest(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
defer server.Stop() |
|
|
|
defer server.Stop() |
|
|
|
client := DialInProc(server) |
|
|
|
client := DialInProc(server) |
|
|
@ -53,6 +55,8 @@ func TestClientRequest(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestClientResponseType(t *testing.T) { |
|
|
|
func TestClientResponseType(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
defer server.Stop() |
|
|
|
defer server.Stop() |
|
|
|
client := DialInProc(server) |
|
|
|
client := DialInProc(server) |
|
|
@ -71,6 +75,8 @@ func TestClientResponseType(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
// This test checks calling a method that returns 'null'.
|
|
|
|
// This test checks calling a method that returns 'null'.
|
|
|
|
func TestClientNullResponse(t *testing.T) { |
|
|
|
func TestClientNullResponse(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
defer server.Stop() |
|
|
|
defer server.Stop() |
|
|
|
|
|
|
|
|
|
|
@ -91,6 +97,8 @@ func TestClientNullResponse(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
// This test checks that server-returned errors with code and data come out of Client.Call.
|
|
|
|
// This test checks that server-returned errors with code and data come out of Client.Call.
|
|
|
|
func TestClientErrorData(t *testing.T) { |
|
|
|
func TestClientErrorData(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
defer server.Stop() |
|
|
|
defer server.Stop() |
|
|
|
client := DialInProc(server) |
|
|
|
client := DialInProc(server) |
|
|
@ -121,6 +129,8 @@ func TestClientErrorData(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestClientBatchRequest(t *testing.T) { |
|
|
|
func TestClientBatchRequest(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
defer server.Stop() |
|
|
|
defer server.Stop() |
|
|
|
client := DialInProc(server) |
|
|
|
client := DialInProc(server) |
|
|
@ -172,6 +182,8 @@ func TestClientBatchRequest(t *testing.T) { |
|
|
|
// This checks that, for HTTP connections, the length of batch responses is validated to
|
|
|
|
// This checks that, for HTTP connections, the length of batch responses is validated to
|
|
|
|
// match the request exactly.
|
|
|
|
// match the request exactly.
|
|
|
|
func TestClientBatchRequest_len(t *testing.T) { |
|
|
|
func TestClientBatchRequest_len(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
b, err := json.Marshal([]jsonrpcMessage{ |
|
|
|
b, err := json.Marshal([]jsonrpcMessage{ |
|
|
|
{Version: "2.0", ID: json.RawMessage("1"), Result: json.RawMessage(`"0x1"`)}, |
|
|
|
{Version: "2.0", ID: json.RawMessage("1"), Result: json.RawMessage(`"0x1"`)}, |
|
|
|
{Version: "2.0", ID: json.RawMessage("2"), Result: json.RawMessage(`"0x2"`)}, |
|
|
|
{Version: "2.0", ID: json.RawMessage("2"), Result: json.RawMessage(`"0x2"`)}, |
|
|
@ -188,6 +200,8 @@ func TestClientBatchRequest_len(t *testing.T) { |
|
|
|
t.Cleanup(s.Close) |
|
|
|
t.Cleanup(s.Close) |
|
|
|
|
|
|
|
|
|
|
|
t.Run("too-few", func(t *testing.T) { |
|
|
|
t.Run("too-few", func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
client, err := Dial(s.URL) |
|
|
|
client, err := Dial(s.URL) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal("failed to dial test server:", err) |
|
|
|
t.Fatal("failed to dial test server:", err) |
|
|
@ -218,6 +232,8 @@ func TestClientBatchRequest_len(t *testing.T) { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
t.Run("too-many", func(t *testing.T) { |
|
|
|
t.Run("too-many", func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
client, err := Dial(s.URL) |
|
|
|
client, err := Dial(s.URL) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal("failed to dial test server:", err) |
|
|
|
t.Fatal("failed to dial test server:", err) |
|
|
@ -249,6 +265,8 @@ func TestClientBatchRequest_len(t *testing.T) { |
|
|
|
// This checks that the client can handle the case where the server doesn't
|
|
|
|
// This checks that the client can handle the case where the server doesn't
|
|
|
|
// respond to all requests in a batch.
|
|
|
|
// respond to all requests in a batch.
|
|
|
|
func TestClientBatchRequestLimit(t *testing.T) { |
|
|
|
func TestClientBatchRequestLimit(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
defer server.Stop() |
|
|
|
defer server.Stop() |
|
|
|
server.SetBatchLimits(2, 100000) |
|
|
|
server.SetBatchLimits(2, 100000) |
|
|
@ -285,6 +303,8 @@ func TestClientBatchRequestLimit(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestClientNotify(t *testing.T) { |
|
|
|
func TestClientNotify(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
defer server.Stop() |
|
|
|
defer server.Stop() |
|
|
|
client := DialInProc(server) |
|
|
|
client := DialInProc(server) |
|
|
@ -392,6 +412,8 @@ func testClientCancel(transport string, t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestClientSubscribeInvalidArg(t *testing.T) { |
|
|
|
func TestClientSubscribeInvalidArg(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
defer server.Stop() |
|
|
|
defer server.Stop() |
|
|
|
client := DialInProc(server) |
|
|
|
client := DialInProc(server) |
|
|
@ -422,6 +444,8 @@ func TestClientSubscribeInvalidArg(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestClientSubscribe(t *testing.T) { |
|
|
|
func TestClientSubscribe(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
defer server.Stop() |
|
|
|
defer server.Stop() |
|
|
|
client := DialInProc(server) |
|
|
|
client := DialInProc(server) |
|
|
@ -454,6 +478,8 @@ func TestClientSubscribe(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
// In this test, the connection drops while Subscribe is waiting for a response.
|
|
|
|
// In this test, the connection drops while Subscribe is waiting for a response.
|
|
|
|
func TestClientSubscribeClose(t *testing.T) { |
|
|
|
func TestClientSubscribeClose(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
service := ¬ificationTestService{ |
|
|
|
service := ¬ificationTestService{ |
|
|
|
gotHangSubscriptionReq: make(chan struct{}), |
|
|
|
gotHangSubscriptionReq: make(chan struct{}), |
|
|
@ -498,6 +524,8 @@ func TestClientSubscribeClose(t *testing.T) { |
|
|
|
// This test reproduces https://github.com/ethereum/go-ethereum/issues/17837 where the
|
|
|
|
// This test reproduces https://github.com/ethereum/go-ethereum/issues/17837 where the
|
|
|
|
// client hangs during shutdown when Unsubscribe races with Client.Close.
|
|
|
|
// client hangs during shutdown when Unsubscribe races with Client.Close.
|
|
|
|
func TestClientCloseUnsubscribeRace(t *testing.T) { |
|
|
|
func TestClientCloseUnsubscribeRace(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
defer server.Stop() |
|
|
|
defer server.Stop() |
|
|
|
|
|
|
|
|
|
|
@ -540,6 +568,8 @@ func (b *unsubscribeBlocker) readBatch() ([]*jsonrpcMessage, bool, error) { |
|
|
|
// not respond.
|
|
|
|
// not respond.
|
|
|
|
// It reproducers the issue https://github.com/ethereum/go-ethereum/issues/30156
|
|
|
|
// It reproducers the issue https://github.com/ethereum/go-ethereum/issues/30156
|
|
|
|
func TestUnsubscribeTimeout(t *testing.T) { |
|
|
|
func TestUnsubscribeTimeout(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
srv := NewServer() |
|
|
|
srv := NewServer() |
|
|
|
srv.RegisterName("nftest", new(notificationTestService)) |
|
|
|
srv.RegisterName("nftest", new(notificationTestService)) |
|
|
|
|
|
|
|
|
|
|
@ -674,6 +704,8 @@ func TestClientSubscriptionChannelClose(t *testing.T) { |
|
|
|
// This test checks that Client doesn't lock up when a single subscriber
|
|
|
|
// This test checks that Client doesn't lock up when a single subscriber
|
|
|
|
// doesn't read subscription events.
|
|
|
|
// doesn't read subscription events.
|
|
|
|
func TestClientNotificationStorm(t *testing.T) { |
|
|
|
func TestClientNotificationStorm(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
defer server.Stop() |
|
|
|
defer server.Stop() |
|
|
|
|
|
|
|
|
|
|
@ -726,6 +758,8 @@ func TestClientNotificationStorm(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestClientSetHeader(t *testing.T) { |
|
|
|
func TestClientSetHeader(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
var gotHeader bool |
|
|
|
var gotHeader bool |
|
|
|
srv := newTestServer() |
|
|
|
srv := newTestServer() |
|
|
|
httpsrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|
|
|
httpsrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|
|
@ -762,6 +796,8 @@ func TestClientSetHeader(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestClientHTTP(t *testing.T) { |
|
|
|
func TestClientHTTP(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
server := newTestServer() |
|
|
|
server := newTestServer() |
|
|
|
defer server.Stop() |
|
|
|
defer server.Stop() |
|
|
|
|
|
|
|
|
|
|
@ -805,6 +841,8 @@ func TestClientHTTP(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestClientReconnect(t *testing.T) { |
|
|
|
func TestClientReconnect(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
startServer := func(addr string) (*Server, net.Listener) { |
|
|
|
startServer := func(addr string) (*Server, net.Listener) { |
|
|
|
srv := newTestServer() |
|
|
|
srv := newTestServer() |
|
|
|
l, err := net.Listen("tcp", addr) |
|
|
|
l, err := net.Listen("tcp", addr) |
|
|
|