forked from cerc-io/plugeth
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:
parent
41671d449f
commit
0f3a1e7f9b
@ -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 := ð.GetBlockHeadersPacket66{
|
req1 := ð.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 {
|
// write second request
|
||||||
t.Fatalf("could not get block headers: %v", err)
|
if err := conn.write66(req2, GetBlockHeaders{}.Code()); err != nil {
|
||||||
return
|
t.Fatalf("failed to write to connection: %v", err)
|
||||||
}
|
}
|
||||||
headers <- recvHeaders
|
// wait for responses
|
||||||
}(headerChan)
|
headers1, err := s.waitForBlockHeadersResponse66(conn, req1.RequestId)
|
||||||
// check headers of second request
|
|
||||||
headers1, err := s.getBlockHeaders66(conn2, req2, req2.RequestId)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not get block headers: %v", err)
|
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")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user