rpc: run tests in parallel (#30384)

Continuation of https://github.com/ethereum/go-ethereum/pull/30381
pull/30769/head
Håvard Anda Estensen 2 days ago committed by GitHub
parent 581e2140f2
commit e20150f888
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 38
      rpc/client_test.go
  2. 20
      rpc/http_test.go
  3. 10
      rpc/server_test.go
  4. 8
      rpc/subscription_test.go
  5. 10
      rpc/types_test.go
  6. 4
      rpc/websocket_test.go

@ -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 := &notificationTestService{ service := &notificationTestService{
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()
@ -804,6 +840,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)

@ -58,24 +58,34 @@ func confirmRequestValidationCode(t *testing.T, method, contentType, body string
} }
func TestHTTPErrorResponseWithDelete(t *testing.T) { func TestHTTPErrorResponseWithDelete(t *testing.T) {
t.Parallel()
confirmRequestValidationCode(t, http.MethodDelete, contentType, "", http.StatusMethodNotAllowed) confirmRequestValidationCode(t, http.MethodDelete, contentType, "", http.StatusMethodNotAllowed)
} }
func TestHTTPErrorResponseWithPut(t *testing.T) { func TestHTTPErrorResponseWithPut(t *testing.T) {
t.Parallel()
confirmRequestValidationCode(t, http.MethodPut, contentType, "", http.StatusMethodNotAllowed) confirmRequestValidationCode(t, http.MethodPut, contentType, "", http.StatusMethodNotAllowed)
} }
func TestHTTPErrorResponseWithMaxContentLength(t *testing.T) { func TestHTTPErrorResponseWithMaxContentLength(t *testing.T) {
t.Parallel()
body := make([]rune, defaultBodyLimit+1) body := make([]rune, defaultBodyLimit+1)
confirmRequestValidationCode(t, confirmRequestValidationCode(t,
http.MethodPost, contentType, string(body), http.StatusRequestEntityTooLarge) http.MethodPost, contentType, string(body), http.StatusRequestEntityTooLarge)
} }
func TestHTTPErrorResponseWithEmptyContentType(t *testing.T) { func TestHTTPErrorResponseWithEmptyContentType(t *testing.T) {
t.Parallel()
confirmRequestValidationCode(t, http.MethodPost, "", "", http.StatusUnsupportedMediaType) confirmRequestValidationCode(t, http.MethodPost, "", "", http.StatusUnsupportedMediaType)
} }
func TestHTTPErrorResponseWithValidRequest(t *testing.T) { func TestHTTPErrorResponseWithValidRequest(t *testing.T) {
t.Parallel()
confirmRequestValidationCode(t, http.MethodPost, contentType, "", 0) confirmRequestValidationCode(t, http.MethodPost, contentType, "", 0)
} }
@ -101,11 +111,15 @@ func confirmHTTPRequestYieldsStatusCode(t *testing.T, method, contentType, body
} }
func TestHTTPResponseWithEmptyGet(t *testing.T) { func TestHTTPResponseWithEmptyGet(t *testing.T) {
t.Parallel()
confirmHTTPRequestYieldsStatusCode(t, http.MethodGet, "", "", http.StatusOK) confirmHTTPRequestYieldsStatusCode(t, http.MethodGet, "", "", http.StatusOK)
} }
// This checks that maxRequestContentLength is not applied to the response of a request. // This checks that maxRequestContentLength is not applied to the response of a request.
func TestHTTPRespBodyUnlimited(t *testing.T) { func TestHTTPRespBodyUnlimited(t *testing.T) {
t.Parallel()
const respLength = defaultBodyLimit * 3 const respLength = defaultBodyLimit * 3
s := NewServer() s := NewServer()
@ -132,6 +146,8 @@ func TestHTTPRespBodyUnlimited(t *testing.T) {
// Tests that an HTTP error results in an HTTPError instance // Tests that an HTTP error results in an HTTPError instance
// being returned with the expected attributes. // being returned with the expected attributes.
func TestHTTPErrorResponse(t *testing.T) { func TestHTTPErrorResponse(t *testing.T) {
t.Parallel()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "error has occurred!", http.StatusTeapot) http.Error(w, "error has occurred!", http.StatusTeapot)
})) }))
@ -169,6 +185,8 @@ func TestHTTPErrorResponse(t *testing.T) {
} }
func TestHTTPPeerInfo(t *testing.T) { func TestHTTPPeerInfo(t *testing.T) {
t.Parallel()
s := newTestServer() s := newTestServer()
defer s.Stop() defer s.Stop()
ts := httptest.NewServer(s) ts := httptest.NewServer(s)
@ -205,6 +223,8 @@ func TestHTTPPeerInfo(t *testing.T) {
} }
func TestNewContextWithHeaders(t *testing.T) { func TestNewContextWithHeaders(t *testing.T) {
t.Parallel()
expectedHeaders := 0 expectedHeaders := 0
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
for i := 0; i < expectedHeaders; i++ { for i := 0; i < expectedHeaders; i++ {

@ -29,6 +29,8 @@ import (
) )
func TestServerRegisterName(t *testing.T) { func TestServerRegisterName(t *testing.T) {
t.Parallel()
server := NewServer() server := NewServer()
service := new(testService) service := new(testService)
@ -53,6 +55,8 @@ func TestServerRegisterName(t *testing.T) {
} }
func TestServer(t *testing.T) { func TestServer(t *testing.T) {
t.Parallel()
files, err := os.ReadDir("testdata") files, err := os.ReadDir("testdata")
if err != nil { if err != nil {
t.Fatal("where'd my testdata go?") t.Fatal("where'd my testdata go?")
@ -64,6 +68,8 @@ func TestServer(t *testing.T) {
path := filepath.Join("testdata", f.Name()) path := filepath.Join("testdata", f.Name())
name := strings.TrimSuffix(f.Name(), filepath.Ext(f.Name())) name := strings.TrimSuffix(f.Name(), filepath.Ext(f.Name()))
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
t.Parallel()
runTestScript(t, path) runTestScript(t, path)
}) })
} }
@ -116,6 +122,8 @@ func runTestScript(t *testing.T, file string) {
// This test checks that responses are delivered for very short-lived connections that // This test checks that responses are delivered for very short-lived connections that
// only carry a single request. // only carry a single request.
func TestServerShortLivedConn(t *testing.T) { func TestServerShortLivedConn(t *testing.T) {
t.Parallel()
server := newTestServer() server := newTestServer()
defer server.Stop() defer server.Stop()
@ -156,6 +164,8 @@ func TestServerShortLivedConn(t *testing.T) {
} }
func TestServerBatchResponseSizeLimit(t *testing.T) { func TestServerBatchResponseSizeLimit(t *testing.T) {
t.Parallel()
server := newTestServer() server := newTestServer()
defer server.Stop() defer server.Stop()
server.SetBatchLimits(100, 60) server.SetBatchLimits(100, 60)

@ -33,6 +33,8 @@ import (
) )
func TestNewID(t *testing.T) { func TestNewID(t *testing.T) {
t.Parallel()
hexchars := "0123456789ABCDEFabcdef" hexchars := "0123456789ABCDEFabcdef"
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
id := string(NewID()) id := string(NewID())
@ -54,6 +56,8 @@ func TestNewID(t *testing.T) {
} }
func TestSubscriptions(t *testing.T) { func TestSubscriptions(t *testing.T) {
t.Parallel()
var ( var (
namespaces = []string{"eth", "bzz"} namespaces = []string{"eth", "bzz"}
service = &notificationTestService{} service = &notificationTestService{}
@ -132,6 +136,8 @@ func TestSubscriptions(t *testing.T) {
// This test checks that unsubscribing works. // This test checks that unsubscribing works.
func TestServerUnsubscribe(t *testing.T) { func TestServerUnsubscribe(t *testing.T) {
t.Parallel()
p1, p2 := net.Pipe() p1, p2 := net.Pipe()
defer p2.Close() defer p2.Close()
@ -260,6 +266,8 @@ func BenchmarkNotify(b *testing.B) {
} }
func TestNotify(t *testing.T) { func TestNotify(t *testing.T) {
t.Parallel()
out := new(bytes.Buffer) out := new(bytes.Buffer)
id := ID("test") id := ID("test")
notifier := &Notifier{ notifier := &Notifier{

@ -26,6 +26,8 @@ import (
) )
func TestBlockNumberJSONUnmarshal(t *testing.T) { func TestBlockNumberJSONUnmarshal(t *testing.T) {
t.Parallel()
tests := []struct { tests := []struct {
input string input string
mustFail bool mustFail bool
@ -70,6 +72,8 @@ func TestBlockNumberJSONUnmarshal(t *testing.T) {
} }
func TestBlockNumberOrHash_UnmarshalJSON(t *testing.T) { func TestBlockNumberOrHash_UnmarshalJSON(t *testing.T) {
t.Parallel()
tests := []struct { tests := []struct {
input string input string
mustFail bool mustFail bool
@ -131,6 +135,8 @@ func TestBlockNumberOrHash_UnmarshalJSON(t *testing.T) {
} }
func TestBlockNumberOrHash_WithNumber_MarshalAndUnmarshal(t *testing.T) { func TestBlockNumberOrHash_WithNumber_MarshalAndUnmarshal(t *testing.T) {
t.Parallel()
tests := []struct { tests := []struct {
name string name string
number int64 number int64
@ -144,6 +150,8 @@ func TestBlockNumberOrHash_WithNumber_MarshalAndUnmarshal(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
t.Parallel()
bnh := BlockNumberOrHashWithNumber(BlockNumber(test.number)) bnh := BlockNumberOrHashWithNumber(BlockNumber(test.number))
marshalled, err := json.Marshal(bnh) marshalled, err := json.Marshal(bnh)
if err != nil { if err != nil {
@ -162,6 +170,8 @@ func TestBlockNumberOrHash_WithNumber_MarshalAndUnmarshal(t *testing.T) {
} }
func TestBlockNumberOrHash_StringAndUnmarshal(t *testing.T) { func TestBlockNumberOrHash_StringAndUnmarshal(t *testing.T) {
t.Parallel()
tests := []BlockNumberOrHash{ tests := []BlockNumberOrHash{
BlockNumberOrHashWithNumber(math.MaxInt64), BlockNumberOrHashWithNumber(math.MaxInt64),
BlockNumberOrHashWithNumber(PendingBlockNumber), BlockNumberOrHashWithNumber(PendingBlockNumber),

@ -174,6 +174,8 @@ func TestWebsocketLargeRead(t *testing.T) {
} }
func TestWebsocketPeerInfo(t *testing.T) { func TestWebsocketPeerInfo(t *testing.T) {
t.Parallel()
var ( var (
s = newTestServer() s = newTestServer()
ts = httptest.NewServer(s.WebsocketHandler([]string{"origin.example.com"})) ts = httptest.NewServer(s.WebsocketHandler([]string{"origin.example.com"}))
@ -259,6 +261,8 @@ func TestClientWebsocketPing(t *testing.T) {
// This checks that the websocket transport can deal with large messages. // This checks that the websocket transport can deal with large messages.
func TestClientWebsocketLargeMessage(t *testing.T) { func TestClientWebsocketLargeMessage(t *testing.T) {
t.Parallel()
var ( var (
srv = NewServer() srv = NewServer()
httpsrv = httptest.NewServer(srv.WebsocketHandler(nil)) httpsrv = httptest.NewServer(srv.WebsocketHandler(nil))

Loading…
Cancel
Save