|
@ -3,12 +3,11 @@ package statesync |
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
"context" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"math/rand" |
|
|
|
|
|
"sync" |
|
|
"sync" |
|
|
"testing" |
|
|
"testing" |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
|
// "github.com/fortytw2/leaktest"
|
|
|
|
|
|
|
|
|
"github.com/fortytw2/leaktest" |
|
|
"github.com/stretchr/testify/mock" |
|
|
"github.com/stretchr/testify/mock" |
|
|
"github.com/stretchr/testify/require" |
|
|
"github.com/stretchr/testify/require" |
|
|
dbm "github.com/tendermint/tm-db" |
|
|
dbm "github.com/tendermint/tm-db" |
|
@ -421,11 +420,11 @@ func TestReactor_Dispatcher(t *testing.T) { |
|
|
|
|
|
|
|
|
func TestReactor_Backfill(t *testing.T) { |
|
|
func TestReactor_Backfill(t *testing.T) { |
|
|
// test backfill algorithm with varying failure rates [0, 10]
|
|
|
// test backfill algorithm with varying failure rates [0, 10]
|
|
|
failureRates := []int{0, 3, 9} |
|
|
|
|
|
|
|
|
failureRates := []int{0, 2, 9} |
|
|
for _, failureRate := range failureRates { |
|
|
for _, failureRate := range failureRates { |
|
|
failureRate := failureRate |
|
|
failureRate := failureRate |
|
|
t.Run(fmt.Sprintf("failure rate: %d", failureRate), func(t *testing.T) { |
|
|
t.Run(fmt.Sprintf("failure rate: %d", failureRate), func(t *testing.T) { |
|
|
// t.Cleanup(leaktest.Check(t))
|
|
|
|
|
|
|
|
|
t.Cleanup(leaktest.CheckTimeout(t, 1*time.Minute)) |
|
|
rts := setup(t, nil, nil, nil, 21) |
|
|
rts := setup(t, nil, nil, nil, 21) |
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
@ -467,7 +466,7 @@ func TestReactor_Backfill(t *testing.T) { |
|
|
factory.MakeBlockIDWithHash(chain[startHeight].Header.Hash()), |
|
|
factory.MakeBlockIDWithHash(chain[startHeight].Header.Hash()), |
|
|
stopTime, |
|
|
stopTime, |
|
|
) |
|
|
) |
|
|
if failureRate > 5 { |
|
|
|
|
|
|
|
|
if failureRate > 3 { |
|
|
require.Error(t, err) |
|
|
require.Error(t, err) |
|
|
} else { |
|
|
} else { |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
@ -506,6 +505,7 @@ func handleLightBlockRequests(t *testing.T, |
|
|
close chan struct{}, |
|
|
close chan struct{}, |
|
|
failureRate int) { |
|
|
failureRate int) { |
|
|
requests := 0 |
|
|
requests := 0 |
|
|
|
|
|
errorCount := 0 |
|
|
for { |
|
|
for { |
|
|
select { |
|
|
select { |
|
|
case envelope := <-receiving: |
|
|
case envelope := <-receiving: |
|
@ -520,7 +520,7 @@ func handleLightBlockRequests(t *testing.T, |
|
|
}, |
|
|
}, |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
switch rand.Intn(3) { |
|
|
|
|
|
|
|
|
switch errorCount % 3 { |
|
|
case 0: // send a different block
|
|
|
case 0: // send a different block
|
|
|
differntLB, err := mockLB(t, int64(msg.Height), factory.DefaultTestTime, factory.MakeBlockID()).ToProto() |
|
|
differntLB, err := mockLB(t, int64(msg.Height), factory.DefaultTestTime, factory.MakeBlockID()).ToProto() |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
@ -539,6 +539,7 @@ func handleLightBlockRequests(t *testing.T, |
|
|
} |
|
|
} |
|
|
case 2: // don't do anything
|
|
|
case 2: // don't do anything
|
|
|
} |
|
|
} |
|
|
|
|
|
errorCount++ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
case <-close: |
|
|
case <-close: |
|
|