Skip to content

Commit f3c19b1

Browse files
estensenholiman
authored andcommitted
rpc: run tests in parallel (#30384)
Continuation of #30381
1 parent 71b32b4 commit f3c19b1

6 files changed

+90
-0
lines changed

rpc/client_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import (
3838
)
3939

4040
func TestClientRequest(t *testing.T) {
41+
t.Parallel()
42+
4143
server := newTestServer()
4244
defer server.Stop()
4345
client := DialInProc(server)
@@ -53,6 +55,8 @@ func TestClientRequest(t *testing.T) {
5355
}
5456

5557
func TestClientResponseType(t *testing.T) {
58+
t.Parallel()
59+
5660
server := newTestServer()
5761
defer server.Stop()
5862
client := DialInProc(server)
@@ -71,6 +75,8 @@ func TestClientResponseType(t *testing.T) {
7175

7276
// This test checks calling a method that returns 'null'.
7377
func TestClientNullResponse(t *testing.T) {
78+
t.Parallel()
79+
7480
server := newTestServer()
7581
defer server.Stop()
7682

@@ -91,6 +97,8 @@ func TestClientNullResponse(t *testing.T) {
9197

9298
// This test checks that server-returned errors with code and data come out of Client.Call.
9399
func TestClientErrorData(t *testing.T) {
100+
t.Parallel()
101+
94102
server := newTestServer()
95103
defer server.Stop()
96104
client := DialInProc(server)
@@ -121,6 +129,8 @@ func TestClientErrorData(t *testing.T) {
121129
}
122130

123131
func TestClientBatchRequest(t *testing.T) {
132+
t.Parallel()
133+
124134
server := newTestServer()
125135
defer server.Stop()
126136
client := DialInProc(server)
@@ -172,6 +182,8 @@ func TestClientBatchRequest(t *testing.T) {
172182
// This checks that, for HTTP connections, the length of batch responses is validated to
173183
// match the request exactly.
174184
func TestClientBatchRequest_len(t *testing.T) {
185+
t.Parallel()
186+
175187
b, err := json.Marshal([]jsonrpcMessage{
176188
{Version: "2.0", ID: json.RawMessage("1"), Result: json.RawMessage(`"0x1"`)},
177189
{Version: "2.0", ID: json.RawMessage("2"), Result: json.RawMessage(`"0x2"`)},
@@ -188,6 +200,8 @@ func TestClientBatchRequest_len(t *testing.T) {
188200
t.Cleanup(s.Close)
189201

190202
t.Run("too-few", func(t *testing.T) {
203+
t.Parallel()
204+
191205
client, err := Dial(s.URL)
192206
if err != nil {
193207
t.Fatal("failed to dial test server:", err)
@@ -218,6 +232,8 @@ func TestClientBatchRequest_len(t *testing.T) {
218232
})
219233

220234
t.Run("too-many", func(t *testing.T) {
235+
t.Parallel()
236+
221237
client, err := Dial(s.URL)
222238
if err != nil {
223239
t.Fatal("failed to dial test server:", err)
@@ -249,6 +265,8 @@ func TestClientBatchRequest_len(t *testing.T) {
249265
// This checks that the client can handle the case where the server doesn't
250266
// respond to all requests in a batch.
251267
func TestClientBatchRequestLimit(t *testing.T) {
268+
t.Parallel()
269+
252270
server := newTestServer()
253271
defer server.Stop()
254272
server.SetBatchLimits(2, 100000)
@@ -285,6 +303,8 @@ func TestClientBatchRequestLimit(t *testing.T) {
285303
}
286304

287305
func TestClientNotify(t *testing.T) {
306+
t.Parallel()
307+
288308
server := newTestServer()
289309
defer server.Stop()
290310
client := DialInProc(server)
@@ -392,6 +412,8 @@ func testClientCancel(transport string, t *testing.T) {
392412
}
393413

394414
func TestClientSubscribeInvalidArg(t *testing.T) {
415+
t.Parallel()
416+
395417
server := newTestServer()
396418
defer server.Stop()
397419
client := DialInProc(server)
@@ -422,6 +444,8 @@ func TestClientSubscribeInvalidArg(t *testing.T) {
422444
}
423445

424446
func TestClientSubscribe(t *testing.T) {
447+
t.Parallel()
448+
425449
server := newTestServer()
426450
defer server.Stop()
427451
client := DialInProc(server)
@@ -454,6 +478,8 @@ func TestClientSubscribe(t *testing.T) {
454478

455479
// In this test, the connection drops while Subscribe is waiting for a response.
456480
func TestClientSubscribeClose(t *testing.T) {
481+
t.Parallel()
482+
457483
server := newTestServer()
458484
service := &notificationTestService{
459485
gotHangSubscriptionReq: make(chan struct{}),
@@ -498,6 +524,8 @@ func TestClientSubscribeClose(t *testing.T) {
498524
// This test reproduces https://github.com/ethereum/go-ethereum/issues/17837 where the
499525
// client hangs during shutdown when Unsubscribe races with Client.Close.
500526
func TestClientCloseUnsubscribeRace(t *testing.T) {
527+
t.Parallel()
528+
501529
server := newTestServer()
502530
defer server.Stop()
503531

@@ -540,6 +568,8 @@ func (b *unsubscribeBlocker) readBatch() ([]*jsonrpcMessage, bool, error) {
540568
// not respond.
541569
// It reproducers the issue https://github.com/ethereum/go-ethereum/issues/30156
542570
func TestUnsubscribeTimeout(t *testing.T) {
571+
t.Parallel()
572+
543573
srv := NewServer()
544574
srv.RegisterName("nftest", new(notificationTestService))
545575

@@ -674,6 +704,8 @@ func TestClientSubscriptionChannelClose(t *testing.T) {
674704
// This test checks that Client doesn't lock up when a single subscriber
675705
// doesn't read subscription events.
676706
func TestClientNotificationStorm(t *testing.T) {
707+
t.Parallel()
708+
677709
server := newTestServer()
678710
defer server.Stop()
679711

@@ -726,6 +758,8 @@ func TestClientNotificationStorm(t *testing.T) {
726758
}
727759

728760
func TestClientSetHeader(t *testing.T) {
761+
t.Parallel()
762+
729763
var gotHeader bool
730764
srv := newTestServer()
731765
httpsrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -762,6 +796,8 @@ func TestClientSetHeader(t *testing.T) {
762796
}
763797

764798
func TestClientHTTP(t *testing.T) {
799+
t.Parallel()
800+
765801
server := newTestServer()
766802
defer server.Stop()
767803

@@ -804,6 +840,8 @@ func TestClientHTTP(t *testing.T) {
804840
}
805841

806842
func TestClientReconnect(t *testing.T) {
843+
t.Parallel()
844+
807845
startServer := func(addr string) (*Server, net.Listener) {
808846
srv := newTestServer()
809847
l, err := net.Listen("tcp", addr)

rpc/http_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,34 @@ func confirmRequestValidationCode(t *testing.T, method, contentType, body string
5858
}
5959

6060
func TestHTTPErrorResponseWithDelete(t *testing.T) {
61+
t.Parallel()
62+
6163
confirmRequestValidationCode(t, http.MethodDelete, contentType, "", http.StatusMethodNotAllowed)
6264
}
6365

6466
func TestHTTPErrorResponseWithPut(t *testing.T) {
67+
t.Parallel()
68+
6569
confirmRequestValidationCode(t, http.MethodPut, contentType, "", http.StatusMethodNotAllowed)
6670
}
6771

6872
func TestHTTPErrorResponseWithMaxContentLength(t *testing.T) {
73+
t.Parallel()
74+
6975
body := make([]rune, defaultBodyLimit+1)
7076
confirmRequestValidationCode(t,
7177
http.MethodPost, contentType, string(body), http.StatusRequestEntityTooLarge)
7278
}
7379

7480
func TestHTTPErrorResponseWithEmptyContentType(t *testing.T) {
81+
t.Parallel()
82+
7583
confirmRequestValidationCode(t, http.MethodPost, "", "", http.StatusUnsupportedMediaType)
7684
}
7785

7886
func TestHTTPErrorResponseWithValidRequest(t *testing.T) {
87+
t.Parallel()
88+
7989
confirmRequestValidationCode(t, http.MethodPost, contentType, "", 0)
8090
}
8191

@@ -101,11 +111,15 @@ func confirmHTTPRequestYieldsStatusCode(t *testing.T, method, contentType, body
101111
}
102112

103113
func TestHTTPResponseWithEmptyGet(t *testing.T) {
114+
t.Parallel()
115+
104116
confirmHTTPRequestYieldsStatusCode(t, http.MethodGet, "", "", http.StatusOK)
105117
}
106118

107119
// This checks that maxRequestContentLength is not applied to the response of a request.
108120
func TestHTTPRespBodyUnlimited(t *testing.T) {
121+
t.Parallel()
122+
109123
const respLength = defaultBodyLimit * 3
110124

111125
s := NewServer()
@@ -132,6 +146,8 @@ func TestHTTPRespBodyUnlimited(t *testing.T) {
132146
// Tests that an HTTP error results in an HTTPError instance
133147
// being returned with the expected attributes.
134148
func TestHTTPErrorResponse(t *testing.T) {
149+
t.Parallel()
150+
135151
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
136152
http.Error(w, "error has occurred!", http.StatusTeapot)
137153
}))
@@ -169,6 +185,8 @@ func TestHTTPErrorResponse(t *testing.T) {
169185
}
170186

171187
func TestHTTPPeerInfo(t *testing.T) {
188+
t.Parallel()
189+
172190
s := newTestServer()
173191
defer s.Stop()
174192
ts := httptest.NewServer(s)
@@ -205,6 +223,8 @@ func TestHTTPPeerInfo(t *testing.T) {
205223
}
206224

207225
func TestNewContextWithHeaders(t *testing.T) {
226+
t.Parallel()
227+
208228
expectedHeaders := 0
209229
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
210230
for i := 0; i < expectedHeaders; i++ {

rpc/server_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
)
3030

3131
func TestServerRegisterName(t *testing.T) {
32+
t.Parallel()
33+
3234
server := NewServer()
3335
service := new(testService)
3436

@@ -53,6 +55,8 @@ func TestServerRegisterName(t *testing.T) {
5355
}
5456

5557
func TestServer(t *testing.T) {
58+
t.Parallel()
59+
5660
files, err := os.ReadDir("testdata")
5761
if err != nil {
5862
t.Fatal("where'd my testdata go?")
@@ -64,6 +68,8 @@ func TestServer(t *testing.T) {
6468
path := filepath.Join("testdata", f.Name())
6569
name := strings.TrimSuffix(f.Name(), filepath.Ext(f.Name()))
6670
t.Run(name, func(t *testing.T) {
71+
t.Parallel()
72+
6773
runTestScript(t, path)
6874
})
6975
}
@@ -116,6 +122,8 @@ func runTestScript(t *testing.T, file string) {
116122
// This test checks that responses are delivered for very short-lived connections that
117123
// only carry a single request.
118124
func TestServerShortLivedConn(t *testing.T) {
125+
t.Parallel()
126+
119127
server := newTestServer()
120128
defer server.Stop()
121129

@@ -156,6 +164,8 @@ func TestServerShortLivedConn(t *testing.T) {
156164
}
157165

158166
func TestServerBatchResponseSizeLimit(t *testing.T) {
167+
t.Parallel()
168+
159169
server := newTestServer()
160170
defer server.Stop()
161171
server.SetBatchLimits(100, 60)

rpc/subscription_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import (
3333
)
3434

3535
func TestNewID(t *testing.T) {
36+
t.Parallel()
37+
3638
hexchars := "0123456789ABCDEFabcdef"
3739
for i := 0; i < 100; i++ {
3840
id := string(NewID())
@@ -54,6 +56,8 @@ func TestNewID(t *testing.T) {
5456
}
5557

5658
func TestSubscriptions(t *testing.T) {
59+
t.Parallel()
60+
5761
var (
5862
namespaces = []string{"eth", "bzz"}
5963
service = &notificationTestService{}
@@ -132,6 +136,8 @@ func TestSubscriptions(t *testing.T) {
132136

133137
// This test checks that unsubscribing works.
134138
func TestServerUnsubscribe(t *testing.T) {
139+
t.Parallel()
140+
135141
p1, p2 := net.Pipe()
136142
defer p2.Close()
137143

@@ -260,6 +266,8 @@ func BenchmarkNotify(b *testing.B) {
260266
}
261267

262268
func TestNotify(t *testing.T) {
269+
t.Parallel()
270+
263271
out := new(bytes.Buffer)
264272
id := ID("test")
265273
notifier := &Notifier{

rpc/types_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
)
2727

2828
func TestBlockNumberJSONUnmarshal(t *testing.T) {
29+
t.Parallel()
30+
2931
tests := []struct {
3032
input string
3133
mustFail bool
@@ -70,6 +72,8 @@ func TestBlockNumberJSONUnmarshal(t *testing.T) {
7072
}
7173

7274
func TestBlockNumberOrHash_UnmarshalJSON(t *testing.T) {
75+
t.Parallel()
76+
7377
tests := []struct {
7478
input string
7579
mustFail bool
@@ -131,6 +135,8 @@ func TestBlockNumberOrHash_UnmarshalJSON(t *testing.T) {
131135
}
132136

133137
func TestBlockNumberOrHash_WithNumber_MarshalAndUnmarshal(t *testing.T) {
138+
t.Parallel()
139+
134140
tests := []struct {
135141
name string
136142
number int64
@@ -144,6 +150,8 @@ func TestBlockNumberOrHash_WithNumber_MarshalAndUnmarshal(t *testing.T) {
144150
}
145151
for _, test := range tests {
146152
t.Run(test.name, func(t *testing.T) {
153+
t.Parallel()
154+
147155
bnh := BlockNumberOrHashWithNumber(BlockNumber(test.number))
148156
marshalled, err := json.Marshal(bnh)
149157
if err != nil {
@@ -162,6 +170,8 @@ func TestBlockNumberOrHash_WithNumber_MarshalAndUnmarshal(t *testing.T) {
162170
}
163171

164172
func TestBlockNumberOrHash_StringAndUnmarshal(t *testing.T) {
173+
t.Parallel()
174+
165175
tests := []BlockNumberOrHash{
166176
BlockNumberOrHashWithNumber(math.MaxInt64),
167177
BlockNumberOrHashWithNumber(PendingBlockNumber),

rpc/websocket_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ func TestWebsocketLargeRead(t *testing.T) {
174174
}
175175

176176
func TestWebsocketPeerInfo(t *testing.T) {
177+
t.Parallel()
178+
177179
var (
178180
s = newTestServer()
179181
ts = httptest.NewServer(s.WebsocketHandler([]string{"origin.example.com"}))
@@ -259,6 +261,8 @@ func TestClientWebsocketPing(t *testing.T) {
259261

260262
// This checks that the websocket transport can deal with large messages.
261263
func TestClientWebsocketLargeMessage(t *testing.T) {
264+
t.Parallel()
265+
262266
var (
263267
srv = NewServer()
264268
httpsrv = httptest.NewServer(srv.WebsocketHandler(nil))

0 commit comments

Comments
 (0)