cmd/devp2p/internal/ethtest: send simultaneous requests on one connection (#22801)

This changes the SimultaneousRequests test to send the requests from the same
connection, as it doesn't really make sense to test whether a node can respond
to two requests with different request IDs from separate connections.
This commit is contained in:
rene 2021-05-05 12:27:27 +02:00 committed by GitHub
parent 41671d449f
commit 0f3a1e7f9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,9 +91,8 @@ func (s *Suite) TestGetBlockHeaders_66(t *utesting.T) {
// headers per request. // headers per request.
func (s *Suite) TestSimultaneousRequests_66(t *utesting.T) { func (s *Suite) TestSimultaneousRequests_66(t *utesting.T) {
// create two connections // create two connections
conn1, conn2 := s.setupConnection66(t), s.setupConnection66(t) conn := s.setupConnection66(t)
defer conn1.Close() defer conn.Close()
defer conn2.Close()
// create two requests // create two requests
req1 := &eth.GetBlockHeadersPacket66{ req1 := &eth.GetBlockHeadersPacket66{
RequestId: 111, RequestId: 111,
@ -117,27 +116,29 @@ func (s *Suite) TestSimultaneousRequests_66(t *utesting.T) {
Reverse: false, Reverse: false,
}, },
} }
// wait for headers for first request // write first request
headerChan := make(chan BlockHeaders, 1) if err := conn.write66(req1, GetBlockHeaders{}.Code()); err != nil {
go func(headers chan BlockHeaders) { t.Fatalf("failed to write to connection: %v", err)
recvHeaders, err := s.getBlockHeaders66(conn1, req1, req1.RequestId)
if err != nil {
t.Fatalf("could not get block headers: %v", err)
return
} }
headers <- recvHeaders // write second request
}(headerChan) if err := conn.write66(req2, GetBlockHeaders{}.Code()); err != nil {
// check headers of second request t.Fatalf("failed to write to connection: %v", err)
headers1, err := s.getBlockHeaders66(conn2, req2, req2.RequestId)
if err != nil {
t.Fatalf("could not get block headers: %v", err)
} }
// wait for responses
headers1, err := s.waitForBlockHeadersResponse66(conn, req1.RequestId)
if err != nil {
t.Fatalf("error while waiting for block headers: %v", err)
}
headers2, err := s.waitForBlockHeadersResponse66(conn, req2.RequestId)
if err != nil {
t.Fatalf("error while waiting for block headers: %v", err)
}
// check headers of both responses
if !headersMatch(t, s.chain, headers1) { if !headersMatch(t, s.chain, headers1) {
t.Fatal("wrong header(s) in response to req2") t.Fatalf("wrong header(s) in response to req1: got %v", headers1)
} }
// check headers of first request if !headersMatch(t, s.chain, headers2) {
if !headersMatch(t, s.chain, <-headerChan) { t.Fatalf("wrong header(s) in response to req2: got %v", headers2)
t.Fatal("wrong header(s) in response to req1")
} }
} }