|
|
@@ -28,6 +28,8 @@ import (
|
|
|
"testing"
|
|
|
"time"
|
|
|
|
|
|
+ "github.com/ethereum/go-ethereum/swarm/testutil"
|
|
|
+
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
@@ -36,7 +38,7 @@ import (
|
|
|
"github.com/ethereum/go-ethereum/swarm/api"
|
|
|
"github.com/ethereum/go-ethereum/swarm/network/simulation"
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
|
|
- colorable "github.com/mattn/go-colorable"
|
|
|
+ "github.com/mattn/go-colorable"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
@@ -57,12 +59,7 @@ func init() {
|
|
|
// static and dynamic Swarm nodes in network simulation, by
|
|
|
// uploading files to every node and retrieving them.
|
|
|
func TestSwarmNetwork(t *testing.T) {
|
|
|
- for _, tc := range []struct {
|
|
|
- name string
|
|
|
- steps []testSwarmNetworkStep
|
|
|
- options *testSwarmNetworkOptions
|
|
|
- disabled bool
|
|
|
- }{
|
|
|
+ var tests = []testSwarmNetworkCase{
|
|
|
{
|
|
|
name: "10_nodes",
|
|
|
steps: []testSwarmNetworkStep{
|
|
|
@@ -86,6 +83,61 @@ func TestSwarmNetwork(t *testing.T) {
|
|
|
SkipCheck: true,
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "dec_inc_node_count",
|
|
|
+ steps: []testSwarmNetworkStep{
|
|
|
+ {
|
|
|
+ nodeCount: 3,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ nodeCount: 1,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ nodeCount: 5,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ options: &testSwarmNetworkOptions{
|
|
|
+ Timeout: 90 * time.Second,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ if *longrunning {
|
|
|
+ tests = append(tests, longRunningCases()...)
|
|
|
+ } else if testutil.RaceEnabled {
|
|
|
+ tests = shortCaseForRace()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, tc := range tests {
|
|
|
+ t.Run(tc.name, func(t *testing.T) {
|
|
|
+ testSwarmNetwork(t, tc.options, tc.steps...)
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type testSwarmNetworkCase struct {
|
|
|
+ name string
|
|
|
+ steps []testSwarmNetworkStep
|
|
|
+ options *testSwarmNetworkOptions
|
|
|
+}
|
|
|
+
|
|
|
+// testSwarmNetworkStep is the configuration
|
|
|
+// for the state of the simulation network.
|
|
|
+type testSwarmNetworkStep struct {
|
|
|
+ // number of swarm nodes that must be in the Up state
|
|
|
+ nodeCount int
|
|
|
+}
|
|
|
+
|
|
|
+// testSwarmNetworkOptions contains optional parameters for running
|
|
|
+// testSwarmNetwork.
|
|
|
+type testSwarmNetworkOptions struct {
|
|
|
+ Timeout time.Duration
|
|
|
+ SkipCheck bool
|
|
|
+}
|
|
|
+
|
|
|
+func longRunningCases() []testSwarmNetworkCase {
|
|
|
+ return []testSwarmNetworkCase{
|
|
|
{
|
|
|
name: "50_nodes",
|
|
|
steps: []testSwarmNetworkStep{
|
|
|
@@ -96,7 +148,6 @@ func TestSwarmNetwork(t *testing.T) {
|
|
|
options: &testSwarmNetworkOptions{
|
|
|
Timeout: 3 * time.Minute,
|
|
|
},
|
|
|
- disabled: !*longrunning,
|
|
|
},
|
|
|
{
|
|
|
name: "50_nodes_skip_check",
|
|
|
@@ -109,7 +160,6 @@ func TestSwarmNetwork(t *testing.T) {
|
|
|
Timeout: 3 * time.Minute,
|
|
|
SkipCheck: true,
|
|
|
},
|
|
|
- disabled: !*longrunning,
|
|
|
},
|
|
|
{
|
|
|
name: "inc_node_count",
|
|
|
@@ -127,7 +177,6 @@ func TestSwarmNetwork(t *testing.T) {
|
|
|
options: &testSwarmNetworkOptions{
|
|
|
Timeout: 90 * time.Second,
|
|
|
},
|
|
|
- disabled: !*longrunning,
|
|
|
},
|
|
|
{
|
|
|
name: "dec_node_count",
|
|
|
@@ -145,24 +194,6 @@ func TestSwarmNetwork(t *testing.T) {
|
|
|
options: &testSwarmNetworkOptions{
|
|
|
Timeout: 90 * time.Second,
|
|
|
},
|
|
|
- disabled: !*longrunning,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "dec_inc_node_count",
|
|
|
- steps: []testSwarmNetworkStep{
|
|
|
- {
|
|
|
- nodeCount: 3,
|
|
|
- },
|
|
|
- {
|
|
|
- nodeCount: 1,
|
|
|
- },
|
|
|
- {
|
|
|
- nodeCount: 5,
|
|
|
- },
|
|
|
- },
|
|
|
- options: &testSwarmNetworkOptions{
|
|
|
- Timeout: 90 * time.Second,
|
|
|
- },
|
|
|
},
|
|
|
{
|
|
|
name: "inc_dec_node_count",
|
|
|
@@ -186,7 +217,6 @@ func TestSwarmNetwork(t *testing.T) {
|
|
|
options: &testSwarmNetworkOptions{
|
|
|
Timeout: 5 * time.Minute,
|
|
|
},
|
|
|
- disabled: !*longrunning,
|
|
|
},
|
|
|
{
|
|
|
name: "inc_dec_node_count_skip_check",
|
|
|
@@ -211,23 +241,25 @@ func TestSwarmNetwork(t *testing.T) {
|
|
|
Timeout: 5 * time.Minute,
|
|
|
SkipCheck: true,
|
|
|
},
|
|
|
- disabled: !*longrunning,
|
|
|
},
|
|
|
- } {
|
|
|
- if tc.disabled {
|
|
|
- continue
|
|
|
- }
|
|
|
- t.Run(tc.name, func(t *testing.T) {
|
|
|
- testSwarmNetwork(t, tc.options, tc.steps...)
|
|
|
- })
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// testSwarmNetworkStep is the configuration
|
|
|
-// for the state of the simulation network.
|
|
|
-type testSwarmNetworkStep struct {
|
|
|
- // number of swarm nodes that must be in the Up state
|
|
|
- nodeCount int
|
|
|
+func shortCaseForRace() []testSwarmNetworkCase {
|
|
|
+ // As for now, Travis with -race can only run 8 nodes
|
|
|
+ return []testSwarmNetworkCase{
|
|
|
+ {
|
|
|
+ name: "8_nodes",
|
|
|
+ steps: []testSwarmNetworkStep{
|
|
|
+ {
|
|
|
+ nodeCount: 8,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ options: &testSwarmNetworkOptions{
|
|
|
+ Timeout: 1 * time.Minute,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// file represents the file uploaded on a particular node.
|
|
|
@@ -244,13 +276,6 @@ type check struct {
|
|
|
nodeID enode.ID
|
|
|
}
|
|
|
|
|
|
-// testSwarmNetworkOptions contains optional parameters for running
|
|
|
-// testSwarmNetwork.
|
|
|
-type testSwarmNetworkOptions struct {
|
|
|
- Timeout time.Duration
|
|
|
- SkipCheck bool
|
|
|
-}
|
|
|
-
|
|
|
// testSwarmNetwork is a helper function used for testing different
|
|
|
// static and dynamic Swarm network simulations.
|
|
|
// It is responsible for:
|
|
|
@@ -259,6 +284,7 @@ type testSwarmNetworkOptions struct {
|
|
|
// - May wait for Kademlia on every node to be healthy.
|
|
|
// - Checking if a file is retrievable from all nodes.
|
|
|
func testSwarmNetwork(t *testing.T, o *testSwarmNetworkOptions, steps ...testSwarmNetworkStep) {
|
|
|
+ t.Helper()
|
|
|
|
|
|
if o == nil {
|
|
|
o = new(testSwarmNetworkOptions)
|