Skip to content

Commit d927c67

Browse files
rojotekfjl
authored andcommitted
eth/downloader: update tests for reliability (#15337)
Updated use of Parallel and added some subtests to help isolate them. Increased timeout in RequestHeadersByNumber so it doesn't time out and causes other tests to break.
1 parent 20fe928 commit d927c67

1 file changed

Lines changed: 49 additions & 12 deletions

File tree

‎eth/downloader/downloader_test.go‎

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ func TestThrottling64Full(t *testing.T) { testThrottling(t, 64, FullSync) }
704704
func TestThrottling64Fast(t *testing.T) { testThrottling(t, 64, FastSync) }
705705

706706
func testThrottling(t *testing.T, protocol int, mode SyncMode) {
707+
t.Parallel()
707708
tester := newTester()
708709
defer tester.terminate()
709710

@@ -1166,6 +1167,8 @@ func TestShiftedHeaderAttack64Fast(t *testing.T) { testShiftedHeaderAttack(t, 6
11661167
func TestShiftedHeaderAttack64Light(t *testing.T) { testShiftedHeaderAttack(t, 64, LightSync) }
11671168

11681169
func testShiftedHeaderAttack(t *testing.T, protocol int, mode SyncMode) {
1170+
t.Parallel()
1171+
11691172
tester := newTester()
11701173
defer tester.terminate()
11711174

@@ -1198,6 +1201,8 @@ func TestInvalidHeaderRollback64Fast(t *testing.T) { testInvalidHeaderRollback(
11981201
func TestInvalidHeaderRollback64Light(t *testing.T) { testInvalidHeaderRollback(t, 64, LightSync) }
11991202

12001203
func testInvalidHeaderRollback(t *testing.T, protocol int, mode SyncMode) {
1204+
t.Parallel()
1205+
12011206
tester := newTester()
12021207
defer tester.terminate()
12031208

@@ -1310,6 +1315,8 @@ func TestBlockHeaderAttackerDropping63(t *testing.T) { testBlockHeaderAttackerDr
13101315
func TestBlockHeaderAttackerDropping64(t *testing.T) { testBlockHeaderAttackerDropping(t, 64) }
13111316

13121317
func testBlockHeaderAttackerDropping(t *testing.T, protocol int) {
1318+
t.Parallel()
1319+
13131320
// Define the disconnection requirement for individual hash fetch errors
13141321
tests := []struct {
13151322
result error
@@ -1665,12 +1672,26 @@ func testFakedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
16651672

16661673
// This test reproduces an issue where unexpected deliveries would
16671674
// block indefinitely if they arrived at the right time.
1668-
func TestDeliverHeadersHang62(t *testing.T) { testDeliverHeadersHang(t, 62, FullSync) }
1669-
func TestDeliverHeadersHang63Full(t *testing.T) { testDeliverHeadersHang(t, 63, FullSync) }
1670-
func TestDeliverHeadersHang63Fast(t *testing.T) { testDeliverHeadersHang(t, 63, FastSync) }
1671-
func TestDeliverHeadersHang64Full(t *testing.T) { testDeliverHeadersHang(t, 64, FullSync) }
1672-
func TestDeliverHeadersHang64Fast(t *testing.T) { testDeliverHeadersHang(t, 64, FastSync) }
1673-
func TestDeliverHeadersHang64Light(t *testing.T) { testDeliverHeadersHang(t, 64, LightSync) }
1675+
// We use data driven subtests to manage this so that it will be parallel on its own
1676+
// and not with the other tests, avoiding intermittent failures.
1677+
func TestDeliverHeadersHang(t *testing.T) {
1678+
testCases := []struct {
1679+
protocol int
1680+
syncMode SyncMode
1681+
}{
1682+
{62, FullSync},
1683+
{63, FullSync},
1684+
{63, FastSync},
1685+
{64, FullSync},
1686+
{64, FastSync},
1687+
{64, LightSync},
1688+
}
1689+
for _, tc := range testCases {
1690+
t.Run(fmt.Sprintf("protocol %d mode %v", tc.protocol, tc.syncMode), func(t *testing.T) {
1691+
testDeliverHeadersHang(t, tc.protocol, tc.syncMode)
1692+
})
1693+
}
1694+
}
16741695

16751696
type floodingTestPeer struct {
16761697
peer Peer
@@ -1703,7 +1724,7 @@ func (ftp *floodingTestPeer) RequestHeadersByNumber(from uint64, count, skip int
17031724
// Deliver the actual requested headers.
17041725
go ftp.peer.RequestHeadersByNumber(from, count, skip, reverse)
17051726
// None of the extra deliveries should block.
1706-
timeout := time.After(15 * time.Second)
1727+
timeout := time.After(60 * time.Second)
17071728
for i := 0; i < cap(deliveriesDone); i++ {
17081729
select {
17091730
case <-deliveriesDone:
@@ -1732,7 +1753,6 @@ func testDeliverHeadersHang(t *testing.T, protocol int, mode SyncMode) {
17321753
tester.downloader.peers.peers["peer"].peer,
17331754
tester,
17341755
}
1735-
17361756
if err := tester.sync("peer", nil, mode); err != nil {
17371757
t.Errorf("sync failed: %v", err)
17381758
}
@@ -1742,12 +1762,28 @@ func testDeliverHeadersHang(t *testing.T, protocol int, mode SyncMode) {
17421762

17431763
// Tests that if fast sync aborts in the critical section, it can restart a few
17441764
// times before giving up.
1745-
func TestFastCriticalRestartsFail63(t *testing.T) { testFastCriticalRestarts(t, 63, false) }
1746-
func TestFastCriticalRestartsFail64(t *testing.T) { testFastCriticalRestarts(t, 64, false) }
1747-
func TestFastCriticalRestartsCont63(t *testing.T) { testFastCriticalRestarts(t, 63, true) }
1748-
func TestFastCriticalRestartsCont64(t *testing.T) { testFastCriticalRestarts(t, 64, true) }
1765+
// We use data driven subtests to manage this so that it will be parallel on its own
1766+
// and not with the other tests, avoiding intermittent failures.
1767+
func TestFastCriticalRestarts(t *testing.T) {
1768+
testCases := []struct {
1769+
protocol int
1770+
progress bool
1771+
}{
1772+
{63, false},
1773+
{64, false},
1774+
{63, true},
1775+
{64, true},
1776+
}
1777+
for _, tc := range testCases {
1778+
t.Run(fmt.Sprintf("protocol %d progress %v", tc.protocol, tc.progress), func(t *testing.T) {
1779+
testFastCriticalRestarts(t, tc.protocol, tc.progress)
1780+
})
1781+
}
1782+
}
17491783

17501784
func testFastCriticalRestarts(t *testing.T, protocol int, progress bool) {
1785+
t.Parallel()
1786+
17511787
tester := newTester()
17521788
defer tester.terminate()
17531789

@@ -1776,6 +1812,7 @@ func testFastCriticalRestarts(t *testing.T, protocol int, progress bool) {
17761812

17771813
// If it's the first failure, pivot should be locked => reenable all others to detect pivot changes
17781814
if i == 0 {
1815+
time.Sleep(150 * time.Millisecond) // Make sure no in-flight requests remain
17791816
if tester.downloader.fsPivotLock == nil {
17801817
time.Sleep(400 * time.Millisecond) // Make sure the first huge timeout expires too
17811818
t.Fatalf("pivot block not locked in after critical section failure")

0 commit comments

Comments
 (0)