Skip to content

Commit

Permalink
Shorten integration and fuzz tests execution (#47)
Browse files Browse the repository at this point in the history
* Parallel execution of integration and fuzz tests
* Get predefined timeout for each round in tests
  • Loading branch information
Stefan-Ethernal authored Apr 5, 2022
1 parent deaee79 commit 14cda84
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 42 deletions.
14 changes: 8 additions & 6 deletions e2e/e2e_node_drop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@ import (
)

func TestE2E_NodeDrop(t *testing.T) {
t.Parallel()
config := &ClusterConfig{
Count: 5,
Name: "node_drop",
Prefix: "ptr",
Count: 5,
Name: "node_drop",
Prefix: "ptr",
RoundTimeout: GetPredefinedTimeout(2 * time.Second),
}

c := NewPBFTCluster(t, config)
c.Start()
// wait for two heights and stop node 1
err := c.WaitForHeight(2, 1*time.Minute)
err := c.WaitForHeight(2, 3*time.Second)
assert.NoError(t, err)

c.StopNode("ptr_0")
err = c.WaitForHeight(15, 1*time.Minute, generateNodeNames(1, 4, "ptr_"))
err = c.WaitForHeight(10, 15*time.Second, generateNodeNames(1, 4, "ptr_"))
assert.NoError(t, err)

// sync dropped node by starting it again
c.StartNode("ptr_0")
err = c.WaitForHeight(15, 1*time.Minute)
err = c.WaitForHeight(10, 15*time.Second)
assert.NoError(t, err)

c.Stop()
Expand Down
10 changes: 6 additions & 4 deletions e2e/e2e_noissue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
)

func TestE2E_NoIssue(t *testing.T) {
t.Parallel()
config := &ClusterConfig{
Count: 5,
Name: "noissue",
Prefix: "noissue",
Count: 5,
Name: "noissue",
Prefix: "noissue",
RoundTimeout: GetPredefinedTimeout(2 * time.Second),
}

c := NewPBFTCluster(t, config, newRandomTransport(300*time.Millisecond))
c := NewPBFTCluster(t, config, newRandomTransport(50*time.Millisecond))
c.Start()
defer c.Stop()

Expand Down
44 changes: 26 additions & 18 deletions e2e/e2e_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import (
)

func TestE2E_Partition_OneMajority(t *testing.T) {
t.Parallel()
const nodesCnt = 5
hook := newPartitionTransport(300 * time.Millisecond)
hook := newPartitionTransport(50 * time.Millisecond)

config := &ClusterConfig{
Count: nodesCnt,
Name: "majority_partition",
Prefix: "prt",
Count: nodesCnt,
Name: "majority_partition",
Prefix: "prt",
RoundTimeout: GetPredefinedTimeout(2 * time.Second),
}

c := NewPBFTCluster(t, config, hook)
Expand Down Expand Up @@ -51,13 +53,15 @@ func TestE2E_Partition_OneMajority(t *testing.T) {
}

func TestE2E_Partition_MajorityCanValidate(t *testing.T) {
const nodesCnt = 7 // N=3F + 1, F = 2
hook := newPartitionTransport(300 * time.Millisecond)
t.Parallel()
const nodesCnt = 7 // N = 3 * F + 1, F = 2
hook := newPartitionTransport(50 * time.Millisecond)

config := &ClusterConfig{
Count: nodesCnt,
Name: "majority_partition",
Prefix: "prt",
Count: nodesCnt,
Name: "majority_partition",
Prefix: "prt",
RoundTimeout: GetPredefinedTimeout(2 * time.Second),
}

c := NewPBFTCluster(t, config, hook)
Expand All @@ -81,13 +85,15 @@ func TestE2E_Partition_MajorityCanValidate(t *testing.T) {
}

func TestE2E_Partition_MajorityCantValidate(t *testing.T) {
const nodesCnt = 7 // N=3F + 1, F = 2
hook := newPartitionTransport(300 * time.Millisecond)
t.Parallel()
const nodesCnt = 7 // N = 3 * F + 1, F = 2
hook := newPartitionTransport(50 * time.Millisecond)

config := &ClusterConfig{
Count: nodesCnt,
Name: "majority_partition",
Prefix: "prt",
Count: nodesCnt,
Name: "majority_partition",
Prefix: "prt",
RoundTimeout: GetPredefinedTimeout(2 * time.Second),
}

c := NewPBFTCluster(t, config, hook)
Expand All @@ -103,13 +109,15 @@ func TestE2E_Partition_MajorityCantValidate(t *testing.T) {
}

func TestE2E_Partition_BigMajorityCantValidate(t *testing.T) {
t.Parallel()
const nodesCnt = 100
hook := newPartitionTransport(300 * time.Millisecond)
hook := newPartitionTransport(50 * time.Millisecond)

config := &ClusterConfig{
Count: nodesCnt,
Name: "majority_partition",
Prefix: "prt",
Count: nodesCnt,
Name: "majority_partition",
Prefix: "prt",
RoundTimeout: GetPredefinedTimeout(2 * time.Second),
}

c := NewPBFTCluster(t, config, hook)
Expand Down
3 changes: 2 additions & 1 deletion e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ func (c *Cluster) WaitForHeight(num uint64, timeout time.Duration, nodes ...[]st
}

timer := time.NewTimer(timeout)
defer timer.Stop()
for {
select {
case <-time.After(200 * time.Millisecond):
case <-time.After(300 * time.Millisecond):
if enough() {
return nil
}
Expand Down
7 changes: 1 addition & 6 deletions e2e/fuzz/replay/replay_message_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (rmc *ReplayMessageCommand) Run(args []string) int {
Name: "fuzz_cluster",
Prefix: prefix,
ReplayMessageNotifier: replayMessagesNotifier,
RoundTimeout: roundTimeout,
RoundTimeout: e2e.GetPredefinedTimeout(time.Millisecond),
TransportHandler: func(to pbft.NodeID, msg *pbft.MessageReq) { replayMessagesNotifier.HandleMessage(to, msg) },
CreateBackend: func() e2e.IntegrationBackend { return &ReplayBackend{messageReader: messageReader} },
}
Expand Down Expand Up @@ -126,11 +126,6 @@ func (rmc *ReplayMessageCommand) NewFlagSet() *flag.FlagSet {
return flagSet
}

// roundTimeout is an implementation of roundTimeout in pbft
func roundTimeout(round uint64) time.Duration {
return time.Millisecond
}

// validateInput parses arguments from CLI and validates their correctness
func (rmc *ReplayMessageCommand) validateInput(args []string) error {
flagSet := rmc.NewFlagSet()
Expand Down
8 changes: 5 additions & 3 deletions e2e/fuzz_network_churn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import (
func TestFuzz_NetworkChurn(t *testing.T) {
isFuzzEnabled(t)

t.Parallel()
rand.Seed(time.Now().Unix())
nodeCount := 20
maxFaulty := nodeCount/3 - 1
const prefix = "ptr_"
config := &ClusterConfig{
Count: nodeCount,
Name: "network_churn",
Prefix: "ptr",
Count: nodeCount,
Name: "network_churn",
Prefix: "ptr",
RoundTimeout: GetPredefinedTimeout(2 * time.Second),
}

c := NewPBFTCluster(t, config)
Expand Down
10 changes: 6 additions & 4 deletions e2e/fuzz_unreliable_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ import (
func TestFuzz_Unreliable_Network(t *testing.T) {
isFuzzEnabled(t)

t.Parallel()
rand.Seed(time.Now().Unix())
nodesCount := 20 + rand.Intn(11) // vary nodes [20,30]
maxFaulty := nodesCount/3 - 1
maxHeight := uint64(40)
currentHeight := uint64(0)
jitterMax := 500 * time.Millisecond
jitterMax := 300 * time.Millisecond
hook := newPartitionTransport(jitterMax)

config := &ClusterConfig{
Count: nodesCount,
Name: "network_unreliable",
Prefix: "prt",
Count: nodesCount,
Name: "network_unreliable",
Prefix: "prt",
RoundTimeout: GetPredefinedTimeout(2 * time.Second),
}

c := NewPBFTCluster(t, config, hook)
Expand Down
9 changes: 9 additions & 0 deletions e2e/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strconv"
"testing"
"time"

"github.com/0xPolygon/pbft-consensus"
)

func generateNodeNames(from int, count int, prefix string) []string {
Expand Down Expand Up @@ -107,3 +109,10 @@ func GetLoggerOutput(name string, logsDir string) io.Writer {
}
return loggerOutput
}

// GetPredefinedTimeout is a closure to the function which is returning given predefined timeout.
func GetPredefinedTimeout(timeout time.Duration) pbft.RoundTimeout {
return func(u uint64) time.Duration {
return timeout
}
}

0 comments on commit 14cda84

Please sign in to comment.