Commit df4b2f3a authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-e2e: Add timeouts to multi-peer sync test (#13801)

parent 7b862463
...@@ -236,7 +236,7 @@ func TestMultiPeerSync(t *testing.T) { ...@@ -236,7 +236,7 @@ func TestMultiPeerSync(t *testing.T) {
hostA, hostB, hostC := hosts[0], hosts[1], hosts[2] hostA, hostB, hostC := hosts[0], hosts[1], hosts[2]
require.Equal(t, hostA.Network().Connectedness(hostB.ID()), network.Connected) require.Equal(t, hostA.Network().Connectedness(hostB.ID()), network.Connected)
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel() defer cancel()
clA, recvA := setupPeer(ctx, hostA) clA, recvA := setupPeer(ctx, hostA)
...@@ -264,11 +264,15 @@ func TestMultiPeerSync(t *testing.T) { ...@@ -264,11 +264,15 @@ func TestMultiPeerSync(t *testing.T) {
// With such large range to request we are going to hit the rate-limits of B and C, // With such large range to request we are going to hit the rate-limits of B and C,
// but that means we'll balance the work between the peers. // but that means we'll balance the work between the peers.
for i := uint64(89); i > 10; i-- { // wait for all payloads for i := uint64(89); i > 10; i-- { // wait for all payloads
e := <-recvA select {
p := e.ExecutionPayload case e := <-recvA:
exp, ok := payloads.getPayload(uint64(p.BlockNumber)) p := e.ExecutionPayload
require.True(t, ok, "expecting known payload") exp, ok := payloads.getPayload(uint64(p.BlockNumber))
require.Equal(t, exp.ExecutionPayload.BlockHash, p.BlockHash, "expecting the correct payload") require.True(t, ok, "expecting known payload")
require.Equal(t, exp.ExecutionPayload.BlockHash, p.BlockHash, "expecting the correct payload")
case <-ctx.Done():
t.Fatal("timed out waiting for payload")
}
} }
// now see if B can sync a range, and fill the gap with a re-request // now see if B can sync a range, and fill the gap with a re-request
...@@ -280,15 +284,19 @@ func TestMultiPeerSync(t *testing.T) { ...@@ -280,15 +284,19 @@ func TestMultiPeerSync(t *testing.T) {
require.True(t, clB.activeRangeRequests.get(rangeReqId), "expecting range request to be active") require.True(t, clB.activeRangeRequests.get(rangeReqId), "expecting range request to be active")
for i := uint64(29); i > 25; i-- { for i := uint64(29); i > 25; i-- {
p := <-recvB select {
exp, ok := payloads.getPayload(uint64(p.ExecutionPayload.BlockNumber)) case p := <-recvB:
require.True(t, ok, "expecting known payload") exp, ok := payloads.getPayload(uint64(p.ExecutionPayload.BlockNumber))
require.Equal(t, exp.ExecutionPayload.BlockHash, p.ExecutionPayload.BlockHash, "expecting the correct payload") require.True(t, ok, "expecting known payload")
require.Equal(t, exp.ExecutionPayload.BlockHash, p.ExecutionPayload.BlockHash, "expecting the correct payload")
case <-ctx.Done():
t.Fatal("timed out waiting for payload")
}
} }
// Wait for the request for block 25 to be made // Wait for the request for block 25 to be made
ctx, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second) childCtx, cancelChild := context.WithTimeout(ctx, 30*time.Second)
defer cancelFunc() defer cancelChild()
requestMade := false requestMade := false
for requestMade != true { for requestMade != true {
select { select {
...@@ -296,7 +304,7 @@ func TestMultiPeerSync(t *testing.T) { ...@@ -296,7 +304,7 @@ func TestMultiPeerSync(t *testing.T) {
if blockNum == 25 { if blockNum == 25 {
requestMade = true requestMade = true
} }
case <-ctx.Done(): case <-childCtx.Done():
t.Fatal("Did not request block 25 in a reasonable time") t.Fatal("Did not request block 25 in a reasonable time")
} }
} }
...@@ -310,10 +318,10 @@ func TestMultiPeerSync(t *testing.T) { ...@@ -310,10 +318,10 @@ func TestMultiPeerSync(t *testing.T) {
// But the re-request checks the status in the main loop, and it may thus look like it's still in-flight, // But the re-request checks the status in the main loop, and it may thus look like it's still in-flight,
// and thus not run the new request. // and thus not run the new request.
// Wait till the failed request is recognized as marked as done, so the re-request actually runs. // Wait till the failed request is recognized as marked as done, so the re-request actually runs.
ctx, cancelFunc = context.WithTimeout(context.Background(), 30*time.Second) childCtx, cancelChild = context.WithTimeout(ctx, 30*time.Second)
defer cancelFunc() defer cancelChild()
for { for {
isInFlight, err := clB.isInFlight(ctx, 25) isInFlight, err := clB.isInFlight(childCtx, 25)
require.NoError(t, err) require.NoError(t, err)
time.Sleep(time.Second) time.Sleep(time.Second)
if !isInFlight { if !isInFlight {
...@@ -328,15 +336,19 @@ func TestMultiPeerSync(t *testing.T) { ...@@ -328,15 +336,19 @@ func TestMultiPeerSync(t *testing.T) {
_, err = clB.RequestL2Range(ctx, payloads.getBlockRef(20), payloads.getBlockRef(26)) _, err = clB.RequestL2Range(ctx, payloads.getBlockRef(20), payloads.getBlockRef(26))
require.NoError(t, err) require.NoError(t, err)
for i := uint64(25); i > 20; i-- { for i := uint64(25); i > 20; i-- {
p := <-recvB select {
exp, ok := payloads.getPayload(uint64(p.ExecutionPayload.BlockNumber)) case p := <-recvB:
require.True(t, ok, "expecting known payload") exp, ok := payloads.getPayload(uint64(p.ExecutionPayload.BlockNumber))
require.Equal(t, exp.ExecutionPayload.BlockHash, p.ExecutionPayload.BlockHash, "expecting the correct payload") require.True(t, ok, "expecting known payload")
require.Equal(t, exp.ParentBeaconBlockRoot, p.ParentBeaconBlockRoot) require.Equal(t, exp.ExecutionPayload.BlockHash, p.ExecutionPayload.BlockHash, "expecting the correct payload")
if cfg.IsEcotone(uint64(p.ExecutionPayload.Timestamp)) { require.Equal(t, exp.ParentBeaconBlockRoot, p.ParentBeaconBlockRoot)
require.NotNil(t, p.ParentBeaconBlockRoot) if cfg.IsEcotone(uint64(p.ExecutionPayload.Timestamp)) {
} else { require.NotNil(t, p.ParentBeaconBlockRoot)
require.Nil(t, p.ParentBeaconBlockRoot) } else {
require.Nil(t, p.ParentBeaconBlockRoot)
}
case <-ctx.Done():
t.Fatal("timed out waiting for payload")
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment