les, light: slim the unit tests

This commit is contained in:
rjl493456442 2019-11-06 16:26:58 +08:00
parent 4e7c7a8d1b
commit e09f8e8647
6 changed files with 33 additions and 23 deletions

View file

@ -110,13 +110,15 @@ func (d *requestDistributor) registerTestPeer(p distPeer) {
d.peerLock.Unlock()
}
// distMaxWait is the maximum waiting time after which further necessary waiting
// times are recalculated based on new feedback from the servers
const distMaxWait = time.Millisecond * 50
var (
// distMaxWait is the maximum waiting time after which further necessary waiting
// times are recalculated based on new feedback from the servers
distMaxWait = time.Millisecond * 50
// waitForPeers is the time window in which a request does not fail even if it
// has no suitable peers to send to at the moment
const waitForPeers = time.Second * 3
// waitForPeers is the time window in which a request does not fail even if it
// has no suitable peers to send to at the moment
waitForPeers = time.Second * 3
)
// main event loop
func (d *requestDistributor) loop() {

View file

@ -86,8 +86,8 @@ func (p *testDistPeer) worker(t *testing.T, checkOrder bool, stop chan struct{})
const (
testDistBufLimit = 10000000
testDistMaxCost = 1000000
testDistPeerCount = 5
testDistReqCount = 5000
testDistPeerCount = 2
testDistReqCount = 10
testDistMaxResendCount = 3
)
@ -128,6 +128,9 @@ func testRequestDistributor(t *testing.T, resend bool) {
go peers[i].worker(t, !resend, stop)
dist.registerTestPeer(peers[i])
}
// Disable the mechanism that we will wait a few time for request
// even there is no suitable peer to send right now.
waitForPeers = 0
var wg sync.WaitGroup

View file

@ -193,6 +193,9 @@ func testOdr(t *testing.T, protocol int, expFail uint64, checkCached bool, fn od
if clientHead.Number.Uint64() != 4 {
t.Fatalf("Failed to sync the chain with server, head: %v", clientHead.Number.Uint64())
}
// Disable the mechanism that we will wait a few time for request
// even there is no suitable peer to send right now.
waitForPeers = 0
test := func(expFail uint64) {
// Mark this as a helper to put the failures at the correct lines
@ -202,6 +205,8 @@ func testOdr(t *testing.T, protocol int, expFail uint64, checkCached bool, fn od
bhash := rawdb.ReadCanonicalHash(server.db, i)
b1 := fn(light.NoOdr, server.db, server.handler.server.chainConfig, server.handler.blockchain, nil, bhash)
// Set the timeout as 1 second here, ensure there is enough time
// for travis to make the action.
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
b2 := fn(ctx, client.db, client.handler.backend.chainConfig, nil, client.handler.backend.blockchain, bhash)
cancel()

View file

@ -89,7 +89,7 @@ func testCheckpointSyncing(t *testing.T, protocol int, syncMode int) {
for {
_, hash, _, err := server.handler.server.oracle.contract.Contract().GetLatestCheckpoint(nil)
if err != nil || hash == [32]byte{} {
time.Sleep(100 * time.Millisecond)
time.Sleep(10 * time.Millisecond)
continue
}
break

View file

@ -71,10 +71,10 @@ var (
var (
// The block frequency for creating checkpoint(only used in test)
sectionSize = big.NewInt(512)
sectionSize = big.NewInt(128)
// The number of confirmations needed to generate a checkpoint(only used in test).
processConfirms = big.NewInt(4)
processConfirms = big.NewInt(1)
// The token bucket buffer limit for testing purpose.
testBufLimit = uint64(1000000)

View file

@ -79,21 +79,21 @@ var (
}
// TestServerIndexerConfig wraps a set of configs as a test indexer config for server side.
TestServerIndexerConfig = &IndexerConfig{
ChtSize: 512,
ChtConfirms: 4,
BloomSize: 64,
BloomConfirms: 4,
BloomTrieSize: 512,
BloomTrieConfirms: 4,
ChtSize: 128,
ChtConfirms: 1,
BloomSize: 16,
BloomConfirms: 1,
BloomTrieSize: 128,
BloomTrieConfirms: 1,
}
// TestClientIndexerConfig wraps a set of configs as a test indexer config for client side.
TestClientIndexerConfig = &IndexerConfig{
ChtSize: 512,
ChtConfirms: 32,
BloomSize: 512,
BloomConfirms: 32,
BloomTrieSize: 512,
BloomTrieConfirms: 32,
ChtSize: 128,
ChtConfirms: 8,
BloomSize: 128,
BloomConfirms: 8,
BloomTrieSize: 128,
BloomTrieConfirms: 8,
}
)