mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm: refactor TestSwarmNetwork case
Extract long running test cases for better visibility.
This commit is contained in:
parent
f33736df56
commit
d9013d84c3
1 changed files with 54 additions and 51 deletions
|
|
@ -36,7 +36,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/swarm/api"
|
"github.com/ethereum/go-ethereum/swarm/api"
|
||||||
"github.com/ethereum/go-ethereum/swarm/network/simulation"
|
"github.com/ethereum/go-ethereum/swarm/network/simulation"
|
||||||
"github.com/ethereum/go-ethereum/swarm/storage"
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
||||||
colorable "github.com/mattn/go-colorable"
|
"github.com/mattn/go-colorable"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -57,12 +57,7 @@ func init() {
|
||||||
// static and dynamic Swarm nodes in network simulation, by
|
// static and dynamic Swarm nodes in network simulation, by
|
||||||
// uploading files to every node and retrieving them.
|
// uploading files to every node and retrieving them.
|
||||||
func TestSwarmNetwork(t *testing.T) {
|
func TestSwarmNetwork(t *testing.T) {
|
||||||
for _, tc := range []struct {
|
var tests = []testSwarmNetworkCase{
|
||||||
name string
|
|
||||||
steps []testSwarmNetworkStep
|
|
||||||
options *testSwarmNetworkOptions
|
|
||||||
disabled bool
|
|
||||||
}{
|
|
||||||
{
|
{
|
||||||
name: "10_nodes",
|
name: "10_nodes",
|
||||||
steps: []testSwarmNetworkStep{
|
steps: []testSwarmNetworkStep{
|
||||||
|
|
@ -86,6 +81,58 @@ func TestSwarmNetwork(t *testing.T) {
|
||||||
SkipCheck: true,
|
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()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
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",
|
name: "50_nodes",
|
||||||
steps: []testSwarmNetworkStep{
|
steps: []testSwarmNetworkStep{
|
||||||
|
|
@ -96,7 +143,6 @@ func TestSwarmNetwork(t *testing.T) {
|
||||||
options: &testSwarmNetworkOptions{
|
options: &testSwarmNetworkOptions{
|
||||||
Timeout: 3 * time.Minute,
|
Timeout: 3 * time.Minute,
|
||||||
},
|
},
|
||||||
disabled: !*longrunning,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "50_nodes_skip_check",
|
name: "50_nodes_skip_check",
|
||||||
|
|
@ -109,7 +155,6 @@ func TestSwarmNetwork(t *testing.T) {
|
||||||
Timeout: 3 * time.Minute,
|
Timeout: 3 * time.Minute,
|
||||||
SkipCheck: true,
|
SkipCheck: true,
|
||||||
},
|
},
|
||||||
disabled: !*longrunning,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "inc_node_count",
|
name: "inc_node_count",
|
||||||
|
|
@ -127,7 +172,6 @@ func TestSwarmNetwork(t *testing.T) {
|
||||||
options: &testSwarmNetworkOptions{
|
options: &testSwarmNetworkOptions{
|
||||||
Timeout: 90 * time.Second,
|
Timeout: 90 * time.Second,
|
||||||
},
|
},
|
||||||
disabled: !*longrunning,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "dec_node_count",
|
name: "dec_node_count",
|
||||||
|
|
@ -145,24 +189,6 @@ func TestSwarmNetwork(t *testing.T) {
|
||||||
options: &testSwarmNetworkOptions{
|
options: &testSwarmNetworkOptions{
|
||||||
Timeout: 90 * time.Second,
|
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",
|
name: "inc_dec_node_count",
|
||||||
|
|
@ -186,7 +212,6 @@ func TestSwarmNetwork(t *testing.T) {
|
||||||
options: &testSwarmNetworkOptions{
|
options: &testSwarmNetworkOptions{
|
||||||
Timeout: 5 * time.Minute,
|
Timeout: 5 * time.Minute,
|
||||||
},
|
},
|
||||||
disabled: !*longrunning,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "inc_dec_node_count_skip_check",
|
name: "inc_dec_node_count_skip_check",
|
||||||
|
|
@ -211,25 +236,10 @@ func TestSwarmNetwork(t *testing.T) {
|
||||||
Timeout: 5 * time.Minute,
|
Timeout: 5 * time.Minute,
|
||||||
SkipCheck: true,
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// file represents the file uploaded on a particular node.
|
// file represents the file uploaded on a particular node.
|
||||||
type file struct {
|
type file struct {
|
||||||
addr storage.Address
|
addr storage.Address
|
||||||
|
|
@ -244,13 +254,6 @@ type check struct {
|
||||||
nodeID enode.ID
|
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
|
// testSwarmNetwork is a helper function used for testing different
|
||||||
// static and dynamic Swarm network simulations.
|
// static and dynamic Swarm network simulations.
|
||||||
// It is responsible for:
|
// It is responsible for:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue