Skip to content

Commit

Permalink
Imporve the execution time of light test
Browse files Browse the repository at this point in the history
  • Loading branch information
tnasu committed Dec 23, 2021
1 parent 433f0cb commit ecf98d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions light/client_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
"time"

"github.com/line/ostracon/libs/sync"

"github.com/line/tm-db/v2/memdb"

"github.com/line/ostracon/libs/log"
Expand All @@ -23,11 +25,23 @@ import (
//
// Remember that none of these benchmarks account for network latency.
var (
benchmarkFullNode = mockp.New(genMockNode(chainID, 1000, 100, 1, bTime))
genesisBlock, _ = benchmarkFullNode.LightBlock(context.Background(), 1)
mu sync.Mutex
// Shouldn't initialize variables here since affecting test (this is for benchmark test)
benchmarkFullNode *mockp.Mock
genesisBlock *types.LightBlock
)

func setupData() {
mu.Lock()
defer mu.Unlock()
if benchmarkFullNode == nil || genesisBlock == nil {
benchmarkFullNode = mockp.New(genMockNode(chainID, 1000, 100, 1, bTime))
genesisBlock, _ = benchmarkFullNode.LightBlock(context.Background(), 1)
}
}

func BenchmarkSequence(b *testing.B) {
setupData()
c, err := light.NewClient(
context.Background(),
chainID,
Expand Down Expand Up @@ -57,6 +71,7 @@ func BenchmarkSequence(b *testing.B) {
}

func BenchmarkBisection(b *testing.B) {
setupData()
c, err := light.NewClient(
context.Background(),
chainID,
Expand Down Expand Up @@ -85,6 +100,7 @@ func BenchmarkBisection(b *testing.B) {
}

func BenchmarkBackwards(b *testing.B) {
setupData()
trustedBlock, _ := benchmarkFullNode.LightBlock(context.Background(), 0)
c, err := light.NewClient(
context.Background(),
Expand Down
4 changes: 2 additions & 2 deletions light/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ var (
valSet,
voterSet,
)
deadNode = mockp.NewDeadMock(chainID)
largeFullNode = mockp.New(genMockNode(chainID, 10, 3, 0, bTime))
deadNode = mockp.NewDeadMock(chainID)
)

func TestValidateTrustOptions(t *testing.T) {
Expand Down Expand Up @@ -923,6 +922,7 @@ func TestClientReplacesPrimaryWithWitnessIfPrimaryIsUnavailable(t *testing.T) {
}

func TestClient_BackwardsVerification(t *testing.T) {
largeFullNode := mockp.New(genMockNode(chainID, 10, 3, 0, bTime))
{
trustHeader, _ := largeFullNode.LightBlock(ctx, 6)
c, err := light.NewClient(
Expand Down

0 comments on commit ecf98d0

Please sign in to comment.