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) {
t.Parallel()
server := newTestServer()
defer server.Stop()
client := DialInProc(server)
@ -53,6 +55,8 @@ func TestClientRequest(t *testing.T) {
}
func TestClientResponseType(t *testing.T) {
t.Parallel()
server := newTestServer()
defer server.Stop()
client := DialInProc(server)
@ -71,6 +75,8 @@ func TestClientResponseType(t *testing.T) {
// This test checks calling a method that returns 'null'.
func TestClientNullResponse(t *testing.T) {
t.Parallel()
server := newTestServer()
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.
func TestClientErrorData(t *testing.T) {
t.Parallel()
server := newTestServer()
defer server.Stop()
client := DialInProc(server)
@ -121,6 +129,8 @@ func TestClientErrorData(t *testing.T) {
}
func TestClientBatchRequest(t *testing.T) {
t.Parallel()
server := newTestServer()
defer server.Stop()
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
// match the request exactly.
func TestClientBatchRequest_len(t *testing.T) {
t.Parallel()
b, err := json.Marshal([]jsonrpcMessage{
{Version: "2.0", ID: json.RawMessage("1"), Result: json.RawMessage(`"0x1"`)},
{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.Run("too-few", func(t *testing.T) {
t.Parallel()
client, err := Dial(s.URL)
if err != nil {
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.Parallel()
client, err := Dial(s.URL)
if err != nil {
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
// respond to all requests in a batch.
func TestClientBatchRequestLimit(t *testing.T) {
t.Parallel()
server := newTestServer()
defer server.Stop()
server.SetBatchLimits(2, 100000)
@ -285,6 +303,8 @@ func TestClientBatchRequestLimit(t *testing.T) {
}
func TestClientNotify(t *testing.T) {
t.Parallel()
server := newTestServer()
defer server.Stop()
client := DialInProc(server)
@ -392,6 +412,8 @@ func testClientCancel(transport string, t *testing.T) {
}
func TestClientSubscribeInvalidArg(t *testing.T) {
t.Parallel()
server := newTestServer()
defer server.Stop()
client := DialInProc(server)
@ -422,6 +444,8 @@ func TestClientSubscribeInvalidArg(t *testing.T) {
}
func TestClientSubscribe(t *testing.T) {
t.Parallel()
server := newTestServer()
defer server.Stop()
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.
func TestClientSubscribeClose(t *testing.T) {
t.Parallel()
server := newTestServer()
service := &notificationTestService{
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
// client hangs during shutdown when Unsubscribe races with Client.Close.
func TestClientCloseUnsubscribeRace(t *testing.T) {
t.Parallel()
server := newTestServer()
defer server.Stop()
@ -540,6 +568,8 @@ func (b *unsubscribeBlocker) readBatch() ([]*jsonrpcMessage, bool, error) {
// not respond.
// It reproducers the issue https://github.com/ethereum/go-ethereum/issues/30156
func TestUnsubscribeTimeout(t *testing.T) {
t.Parallel()
srv := NewServer()
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
// doesn't read subscription events.
func TestClientNotificationStorm(t *testing.T) {
t.Parallel()
server := newTestServer()
defer server.Stop()
@ -726,6 +758,8 @@ func TestClientNotificationStorm(t *testing.T) {
}
func TestClientSetHeader(t *testing.T) {
t.Parallel()
var gotHeader bool
srv := newTestServer()
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) {
t.Parallel()
server := newTestServer()
defer server.Stop()
@ -804,6 +840,8 @@ func TestClientHTTP(t *testing.T) {
}
func TestClientReconnect(t *testing.T) {
t.Parallel()
startServer := func(addr string) (*Server, net.Listener) {
srv := newTestServer()
l, err := net.Listen("tcp", addr)

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

@ -29,6 +29,8 @@ import (
)
func TestServerRegisterName(t *testing.T) {
t.Parallel()
server := NewServer()
service := new(testService)
@ -53,6 +55,8 @@ func TestServerRegisterName(t *testing.T) {
}
func TestServer(t *testing.T) {
t.Parallel()
files, err := os.ReadDir("testdata")
if err != nil {
t.Fatal("where'd my testdata go?")
@ -64,6 +68,8 @@ func TestServer(t *testing.T) {
path := filepath.Join("testdata", f.Name())
name := strings.TrimSuffix(f.Name(), filepath.Ext(f.Name()))
t.Run(name, func(t *testing.T) {
t.Parallel()
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
// only carry a single request.
func TestServerShortLivedConn(t *testing.T) {
t.Parallel()
server := newTestServer()
defer server.Stop()
@ -156,6 +164,8 @@ func TestServerShortLivedConn(t *testing.T) {
}
func TestServerBatchResponseSizeLimit(t *testing.T) {
t.Parallel()
server := newTestServer()
defer server.Stop()
server.SetBatchLimits(100, 60)

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

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

@ -174,6 +174,8 @@ func TestWebsocketLargeRead(t *testing.T) {
}
func TestWebsocketPeerInfo(t *testing.T) {
t.Parallel()
var (
s = newTestServer()
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.
func TestClientWebsocketLargeMessage(t *testing.T) {
t.Parallel()
var (
srv = NewServer()
httpsrv = httptest.NewServer(srv.WebsocketHandler(nil))

Loading…
Cancel
Save