plugeth/swarm/network_test.go

533 lines
12 KiB
Go
Raw Normal View History

2018-06-20 12:06:27 +00:00
// Copyright 2018 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package swarm
import (
"context"
"flag"
"fmt"
"io/ioutil"
"math/rand"
"os"
"sync"
"sync/atomic"
"testing"
"time"
Ci race detector handle failing tests (#19143) * swarm/storage: increase mget timeout in common_test.go TestDbStoreCorrect_1k sometimes timed out with -race on Travis. --- FAIL: TestDbStoreCorrect_1k (24.63s) common_test.go:194: testStore failed: timed out after 10s * swarm: remove unused vars from TestSnapshotSyncWithServer nodeCount and chunkCount is returned from setupSim and those values we use. * swarm: move race/norace helpers from stream to testutil As we will need to use the flag in other packages, too. * swarm: refactor TestSwarmNetwork case Extract long running test cases for better visibility. * swarm/network: skip TestSyncingViaGlobalSync with -race As panics on Travis. panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7e351b] * swarm: run TestSwarmNetwork with fewer nodes with -race As otherwise we always get test failure with `network_test.go:374: context deadline exceeded` even with raised `Timeout`. * swarm/network: run TestDeliveryFromNodes with fewer nodes with -race Test on Travis times out with 8 or more nodes if -race flag is present. * swarm/network: smaller node count for discovery tests with -race TestDiscoveryPersistenceSimulationSimAdapters failed on Travis with `-race` flag present. The failure was due to extensive memory usage, coming from the CGO runtime. Using a smaller node count resolves the issue. === RUN TestDiscoveryPersistenceSimulationSimAdapter ==7227==ERROR: ThreadSanitizer failed to allocate 0x80000 (524288) bytes of clock allocator (error code: 12) FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6976 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) FAIL github.com/ethereum/go-ethereum/swarm/network/simulations/discovery 804.826s * swarm/network: run TestFileRetrieval with fewer nodes with -race Otherwise we get a failure due to extensive memory usage, as the CGO runtime cannot allocate more bytes. === RUN TestFileRetrieval ==7366==ERROR: ThreadSanitizer failed to allocate 0x80000 (524288) bytes of clock allocator (error code: 12) FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6976 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) FAIL github.com/ethereum/go-ethereum/swarm/network/stream 155.165s * swarm/network: run TestRetrieval with fewer nodes with -race Otherwise we get a failure due to extensive memory usage, as the CGO runtime cannot allocate more bytes ("ThreadSanitizer failed to allocate"). * swarm/network: skip flaky TestGetSubscriptionsRPC on Travis w/ -race Test fails a lot with something like: streamer_test.go:1332: Real subscriptions and expected amount don't match; real: 0, expected: 20 * swarm/storage: skip TestDB_SubscribePull* tests on Travis w/ -race Travis just hangs... ok github.com/ethereum/go-ethereum/swarm/storage/feed/lookup 1.307s keepalive keepalive keepalive or panics after a while. Without these tests the race detector job is now stable. Let's invetigate these tests in a separate issue: https://github.com/ethersphere/go-ethereum/issues/1245
2019-02-20 21:57:42 +00:00
"github.com/ethereum/go-ethereum/swarm/testutil"
2018-06-20 12:06:27 +00:00
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
all: new p2p node representation (#17643) Package p2p/enode provides a generalized representation of p2p nodes which can contain arbitrary information in key/value pairs. It is also the new home for the node database. The "v4" identity scheme is also moved here from p2p/enr to remove the dependency on Ethereum crypto from that package. Record signature handling is changed significantly. The identity scheme registry is removed and acceptable schemes must be passed to any method that needs identity. This means records must now be validated explicitly after decoding. The enode API is designed to make signature handling easy and safe: most APIs around the codebase work with enode.Node, which is a wrapper around a valid record. Going from enr.Record to enode.Node requires a valid signature. * p2p/discover: port to p2p/enode This ports the discovery code to the new node representation in p2p/enode. The wire protocol is unchanged, this can be considered a refactoring change. The Kademlia table can now deal with nodes using an arbitrary identity scheme. This requires a few incompatible API changes: - Table.Lookup is not available anymore. It used to take a public key as argument because v4 protocol requires one. Its replacement is LookupRandom. - Table.Resolve takes *enode.Node instead of NodeID. This is also for v4 protocol compatibility because nodes cannot be looked up by ID alone. - Types Node and NodeID are gone. Further commits in the series will be fixes all over the the codebase to deal with those removals. * p2p: port to p2p/enode and discovery changes This adapts package p2p to the changes in p2p/discover. All uses of discover.Node and discover.NodeID are replaced by their equivalents from p2p/enode. New API is added to retrieve the enode.Node instance of a peer. The behavior of Server.Self with discovery disabled is improved. It now tries much harder to report a working IP address, falling back to 127.0.0.1 if no suitable address can be determined through other means. These changes were needed for tests of other packages later in the series. * p2p/simulations, p2p/testing: port to p2p/enode No surprises here, mostly replacements of discover.Node, discover.NodeID with their new equivalents. The 'interesting' API changes are: - testing.ProtocolSession tracks complete nodes, not just their IDs. - adapters.NodeConfig has a new method to create a complete node. These changes were needed to make swarm tests work. Note that the NodeID change makes the code incompatible with old simulation snapshots. * whisper/whisperv5, whisper/whisperv6: port to p2p/enode This port was easy because whisper uses []byte for node IDs and URL strings in the API. * eth: port to p2p/enode Again, easy to port because eth uses strings for node IDs and doesn't care about node information in any way. * les: port to p2p/enode Apart from replacing discover.NodeID with enode.ID, most changes are in the server pool code. It now deals with complete nodes instead of (Pubkey, IP, Port) triples. The database format is unchanged for now, but we should probably change it to use the node database later. * node: port to p2p/enode This change simply replaces discover.Node and discover.NodeID with their new equivalents. * swarm/network: port to p2p/enode Swarm has its own node address representation, BzzAddr, containing both an overlay address (the hash of a secp256k1 public key) and an underlay address (enode:// URL). There are no changes to the BzzAddr format in this commit, but certain operations such as creating a BzzAddr from a node ID are now impossible because node IDs aren't public keys anymore. Most swarm-related changes in the series remove uses of NewAddrFromNodeID, replacing it with NewAddr which takes a complete node as argument. ToOverlayAddr is removed because we can just use the node ID directly.
2018-09-24 22:59:00 +00:00
"github.com/ethereum/go-ethereum/p2p/enode"
2018-06-20 12:06:27 +00:00
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
"github.com/ethereum/go-ethereum/swarm/api"
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
"github.com/ethereum/go-ethereum/swarm/network/simulation"
2018-06-20 12:06:27 +00:00
"github.com/ethereum/go-ethereum/swarm/storage"
Ci race detector handle failing tests (#19143) * swarm/storage: increase mget timeout in common_test.go TestDbStoreCorrect_1k sometimes timed out with -race on Travis. --- FAIL: TestDbStoreCorrect_1k (24.63s) common_test.go:194: testStore failed: timed out after 10s * swarm: remove unused vars from TestSnapshotSyncWithServer nodeCount and chunkCount is returned from setupSim and those values we use. * swarm: move race/norace helpers from stream to testutil As we will need to use the flag in other packages, too. * swarm: refactor TestSwarmNetwork case Extract long running test cases for better visibility. * swarm/network: skip TestSyncingViaGlobalSync with -race As panics on Travis. panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7e351b] * swarm: run TestSwarmNetwork with fewer nodes with -race As otherwise we always get test failure with `network_test.go:374: context deadline exceeded` even with raised `Timeout`. * swarm/network: run TestDeliveryFromNodes with fewer nodes with -race Test on Travis times out with 8 or more nodes if -race flag is present. * swarm/network: smaller node count for discovery tests with -race TestDiscoveryPersistenceSimulationSimAdapters failed on Travis with `-race` flag present. The failure was due to extensive memory usage, coming from the CGO runtime. Using a smaller node count resolves the issue. === RUN TestDiscoveryPersistenceSimulationSimAdapter ==7227==ERROR: ThreadSanitizer failed to allocate 0x80000 (524288) bytes of clock allocator (error code: 12) FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6976 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) FAIL github.com/ethereum/go-ethereum/swarm/network/simulations/discovery 804.826s * swarm/network: run TestFileRetrieval with fewer nodes with -race Otherwise we get a failure due to extensive memory usage, as the CGO runtime cannot allocate more bytes. === RUN TestFileRetrieval ==7366==ERROR: ThreadSanitizer failed to allocate 0x80000 (524288) bytes of clock allocator (error code: 12) FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6976 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) FAIL github.com/ethereum/go-ethereum/swarm/network/stream 155.165s * swarm/network: run TestRetrieval with fewer nodes with -race Otherwise we get a failure due to extensive memory usage, as the CGO runtime cannot allocate more bytes ("ThreadSanitizer failed to allocate"). * swarm/network: skip flaky TestGetSubscriptionsRPC on Travis w/ -race Test fails a lot with something like: streamer_test.go:1332: Real subscriptions and expected amount don't match; real: 0, expected: 20 * swarm/storage: skip TestDB_SubscribePull* tests on Travis w/ -race Travis just hangs... ok github.com/ethereum/go-ethereum/swarm/storage/feed/lookup 1.307s keepalive keepalive keepalive or panics after a while. Without these tests the race detector job is now stable. Let's invetigate these tests in a separate issue: https://github.com/ethersphere/go-ethereum/issues/1245
2019-02-20 21:57:42 +00:00
"github.com/mattn/go-colorable"
2018-06-20 12:06:27 +00:00
)
var (
loglevel = flag.Int("loglevel", 2, "verbosity of logs")
longrunning = flag.Bool("longrunning", false, "do run long-running tests")
waitKademlia = flag.Bool("waitkademlia", false, "wait for healthy kademlia before checking files availability")
)
func init() {
rand.Seed(time.Now().UnixNano())
flag.Parse()
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(true))))
}
// TestSwarmNetwork runs a series of test simulations with
// static and dynamic Swarm nodes in network simulation, by
// uploading files to every node and retrieving them.
func TestSwarmNetwork(t *testing.T) {
Ci race detector handle failing tests (#19143) * swarm/storage: increase mget timeout in common_test.go TestDbStoreCorrect_1k sometimes timed out with -race on Travis. --- FAIL: TestDbStoreCorrect_1k (24.63s) common_test.go:194: testStore failed: timed out after 10s * swarm: remove unused vars from TestSnapshotSyncWithServer nodeCount and chunkCount is returned from setupSim and those values we use. * swarm: move race/norace helpers from stream to testutil As we will need to use the flag in other packages, too. * swarm: refactor TestSwarmNetwork case Extract long running test cases for better visibility. * swarm/network: skip TestSyncingViaGlobalSync with -race As panics on Travis. panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7e351b] * swarm: run TestSwarmNetwork with fewer nodes with -race As otherwise we always get test failure with `network_test.go:374: context deadline exceeded` even with raised `Timeout`. * swarm/network: run TestDeliveryFromNodes with fewer nodes with -race Test on Travis times out with 8 or more nodes if -race flag is present. * swarm/network: smaller node count for discovery tests with -race TestDiscoveryPersistenceSimulationSimAdapters failed on Travis with `-race` flag present. The failure was due to extensive memory usage, coming from the CGO runtime. Using a smaller node count resolves the issue. === RUN TestDiscoveryPersistenceSimulationSimAdapter ==7227==ERROR: ThreadSanitizer failed to allocate 0x80000 (524288) bytes of clock allocator (error code: 12) FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6976 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) FAIL github.com/ethereum/go-ethereum/swarm/network/simulations/discovery 804.826s * swarm/network: run TestFileRetrieval with fewer nodes with -race Otherwise we get a failure due to extensive memory usage, as the CGO runtime cannot allocate more bytes. === RUN TestFileRetrieval ==7366==ERROR: ThreadSanitizer failed to allocate 0x80000 (524288) bytes of clock allocator (error code: 12) FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6976 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) FAIL github.com/ethereum/go-ethereum/swarm/network/stream 155.165s * swarm/network: run TestRetrieval with fewer nodes with -race Otherwise we get a failure due to extensive memory usage, as the CGO runtime cannot allocate more bytes ("ThreadSanitizer failed to allocate"). * swarm/network: skip flaky TestGetSubscriptionsRPC on Travis w/ -race Test fails a lot with something like: streamer_test.go:1332: Real subscriptions and expected amount don't match; real: 0, expected: 20 * swarm/storage: skip TestDB_SubscribePull* tests on Travis w/ -race Travis just hangs... ok github.com/ethereum/go-ethereum/swarm/storage/feed/lookup 1.307s keepalive keepalive keepalive or panics after a while. Without these tests the race detector job is now stable. Let's invetigate these tests in a separate issue: https://github.com/ethersphere/go-ethereum/issues/1245
2019-02-20 21:57:42 +00:00
var tests = []testSwarmNetworkCase{
2018-06-20 12:06:27 +00:00
{
name: "10_nodes",
steps: []testSwarmNetworkStep{
{
nodeCount: 10,
},
},
options: &testSwarmNetworkOptions{
Timeout: 45 * time.Second,
},
},
{
name: "10_nodes_skip_check",
steps: []testSwarmNetworkStep{
{
nodeCount: 10,
},
},
options: &testSwarmNetworkOptions{
Timeout: 45 * time.Second,
SkipCheck: true,
},
},
Ci race detector handle failing tests (#19143) * swarm/storage: increase mget timeout in common_test.go TestDbStoreCorrect_1k sometimes timed out with -race on Travis. --- FAIL: TestDbStoreCorrect_1k (24.63s) common_test.go:194: testStore failed: timed out after 10s * swarm: remove unused vars from TestSnapshotSyncWithServer nodeCount and chunkCount is returned from setupSim and those values we use. * swarm: move race/norace helpers from stream to testutil As we will need to use the flag in other packages, too. * swarm: refactor TestSwarmNetwork case Extract long running test cases for better visibility. * swarm/network: skip TestSyncingViaGlobalSync with -race As panics on Travis. panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7e351b] * swarm: run TestSwarmNetwork with fewer nodes with -race As otherwise we always get test failure with `network_test.go:374: context deadline exceeded` even with raised `Timeout`. * swarm/network: run TestDeliveryFromNodes with fewer nodes with -race Test on Travis times out with 8 or more nodes if -race flag is present. * swarm/network: smaller node count for discovery tests with -race TestDiscoveryPersistenceSimulationSimAdapters failed on Travis with `-race` flag present. The failure was due to extensive memory usage, coming from the CGO runtime. Using a smaller node count resolves the issue. === RUN TestDiscoveryPersistenceSimulationSimAdapter ==7227==ERROR: ThreadSanitizer failed to allocate 0x80000 (524288) bytes of clock allocator (error code: 12) FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6976 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) FAIL github.com/ethereum/go-ethereum/swarm/network/simulations/discovery 804.826s * swarm/network: run TestFileRetrieval with fewer nodes with -race Otherwise we get a failure due to extensive memory usage, as the CGO runtime cannot allocate more bytes. === RUN TestFileRetrieval ==7366==ERROR: ThreadSanitizer failed to allocate 0x80000 (524288) bytes of clock allocator (error code: 12) FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6976 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) FAIL github.com/ethereum/go-ethereum/swarm/network/stream 155.165s * swarm/network: run TestRetrieval with fewer nodes with -race Otherwise we get a failure due to extensive memory usage, as the CGO runtime cannot allocate more bytes ("ThreadSanitizer failed to allocate"). * swarm/network: skip flaky TestGetSubscriptionsRPC on Travis w/ -race Test fails a lot with something like: streamer_test.go:1332: Real subscriptions and expected amount don't match; real: 0, expected: 20 * swarm/storage: skip TestDB_SubscribePull* tests on Travis w/ -race Travis just hangs... ok github.com/ethereum/go-ethereum/swarm/storage/feed/lookup 1.307s keepalive keepalive keepalive or panics after a while. Without these tests the race detector job is now stable. Let's invetigate these tests in a separate issue: https://github.com/ethersphere/go-ethereum/issues/1245
2019-02-20 21:57:42 +00:00
{
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{
2018-06-20 12:06:27 +00:00
{
name: "50_nodes",
2018-06-20 12:06:27 +00:00
steps: []testSwarmNetworkStep{
{
nodeCount: 50,
2018-06-20 12:06:27 +00:00
},
},
options: &testSwarmNetworkOptions{
Timeout: 3 * time.Minute,
},
},
{
name: "50_nodes_skip_check",
2018-06-20 12:06:27 +00:00
steps: []testSwarmNetworkStep{
{
nodeCount: 50,
2018-06-20 12:06:27 +00:00
},
},
options: &testSwarmNetworkOptions{
Timeout: 3 * time.Minute,
SkipCheck: true,
},
},
{
name: "inc_node_count",
steps: []testSwarmNetworkStep{
{
nodeCount: 2,
},
{
nodeCount: 5,
},
{
nodeCount: 10,
},
},
options: &testSwarmNetworkOptions{
Timeout: 90 * time.Second,
},
},
{
name: "dec_node_count",
steps: []testSwarmNetworkStep{
{
nodeCount: 10,
},
{
nodeCount: 6,
},
{
nodeCount: 3,
},
},
options: &testSwarmNetworkOptions{
Timeout: 90 * time.Second,
},
},
{
name: "inc_dec_node_count",
steps: []testSwarmNetworkStep{
{
nodeCount: 3,
},
{
nodeCount: 5,
},
{
nodeCount: 25,
},
{
nodeCount: 10,
},
{
nodeCount: 4,
},
},
options: &testSwarmNetworkOptions{
Timeout: 5 * time.Minute,
},
},
{
name: "inc_dec_node_count_skip_check",
steps: []testSwarmNetworkStep{
{
nodeCount: 3,
},
{
nodeCount: 5,
},
{
nodeCount: 25,
},
{
nodeCount: 10,
},
{
nodeCount: 4,
},
},
options: &testSwarmNetworkOptions{
Timeout: 5 * time.Minute,
SkipCheck: true,
},
},
}
}
Ci race detector handle failing tests (#19143) * swarm/storage: increase mget timeout in common_test.go TestDbStoreCorrect_1k sometimes timed out with -race on Travis. --- FAIL: TestDbStoreCorrect_1k (24.63s) common_test.go:194: testStore failed: timed out after 10s * swarm: remove unused vars from TestSnapshotSyncWithServer nodeCount and chunkCount is returned from setupSim and those values we use. * swarm: move race/norace helpers from stream to testutil As we will need to use the flag in other packages, too. * swarm: refactor TestSwarmNetwork case Extract long running test cases for better visibility. * swarm/network: skip TestSyncingViaGlobalSync with -race As panics on Travis. panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7e351b] * swarm: run TestSwarmNetwork with fewer nodes with -race As otherwise we always get test failure with `network_test.go:374: context deadline exceeded` even with raised `Timeout`. * swarm/network: run TestDeliveryFromNodes with fewer nodes with -race Test on Travis times out with 8 or more nodes if -race flag is present. * swarm/network: smaller node count for discovery tests with -race TestDiscoveryPersistenceSimulationSimAdapters failed on Travis with `-race` flag present. The failure was due to extensive memory usage, coming from the CGO runtime. Using a smaller node count resolves the issue. === RUN TestDiscoveryPersistenceSimulationSimAdapter ==7227==ERROR: ThreadSanitizer failed to allocate 0x80000 (524288) bytes of clock allocator (error code: 12) FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6976 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) FAIL github.com/ethereum/go-ethereum/swarm/network/simulations/discovery 804.826s * swarm/network: run TestFileRetrieval with fewer nodes with -race Otherwise we get a failure due to extensive memory usage, as the CGO runtime cannot allocate more bytes. === RUN TestFileRetrieval ==7366==ERROR: ThreadSanitizer failed to allocate 0x80000 (524288) bytes of clock allocator (error code: 12) FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6976 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) FAIL github.com/ethereum/go-ethereum/swarm/network/stream 155.165s * swarm/network: run TestRetrieval with fewer nodes with -race Otherwise we get a failure due to extensive memory usage, as the CGO runtime cannot allocate more bytes ("ThreadSanitizer failed to allocate"). * swarm/network: skip flaky TestGetSubscriptionsRPC on Travis w/ -race Test fails a lot with something like: streamer_test.go:1332: Real subscriptions and expected amount don't match; real: 0, expected: 20 * swarm/storage: skip TestDB_SubscribePull* tests on Travis w/ -race Travis just hangs... ok github.com/ethereum/go-ethereum/swarm/storage/feed/lookup 1.307s keepalive keepalive keepalive or panics after a while. Without these tests the race detector job is now stable. Let's invetigate these tests in a separate issue: https://github.com/ethersphere/go-ethereum/issues/1245
2019-02-20 21:57:42 +00:00
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,
},
},
}
2018-06-20 12:06:27 +00:00
}
// file represents the file uploaded on a particular node.
type file struct {
addr storage.Address
data string
all: new p2p node representation (#17643) Package p2p/enode provides a generalized representation of p2p nodes which can contain arbitrary information in key/value pairs. It is also the new home for the node database. The "v4" identity scheme is also moved here from p2p/enr to remove the dependency on Ethereum crypto from that package. Record signature handling is changed significantly. The identity scheme registry is removed and acceptable schemes must be passed to any method that needs identity. This means records must now be validated explicitly after decoding. The enode API is designed to make signature handling easy and safe: most APIs around the codebase work with enode.Node, which is a wrapper around a valid record. Going from enr.Record to enode.Node requires a valid signature. * p2p/discover: port to p2p/enode This ports the discovery code to the new node representation in p2p/enode. The wire protocol is unchanged, this can be considered a refactoring change. The Kademlia table can now deal with nodes using an arbitrary identity scheme. This requires a few incompatible API changes: - Table.Lookup is not available anymore. It used to take a public key as argument because v4 protocol requires one. Its replacement is LookupRandom. - Table.Resolve takes *enode.Node instead of NodeID. This is also for v4 protocol compatibility because nodes cannot be looked up by ID alone. - Types Node and NodeID are gone. Further commits in the series will be fixes all over the the codebase to deal with those removals. * p2p: port to p2p/enode and discovery changes This adapts package p2p to the changes in p2p/discover. All uses of discover.Node and discover.NodeID are replaced by their equivalents from p2p/enode. New API is added to retrieve the enode.Node instance of a peer. The behavior of Server.Self with discovery disabled is improved. It now tries much harder to report a working IP address, falling back to 127.0.0.1 if no suitable address can be determined through other means. These changes were needed for tests of other packages later in the series. * p2p/simulations, p2p/testing: port to p2p/enode No surprises here, mostly replacements of discover.Node, discover.NodeID with their new equivalents. The 'interesting' API changes are: - testing.ProtocolSession tracks complete nodes, not just their IDs. - adapters.NodeConfig has a new method to create a complete node. These changes were needed to make swarm tests work. Note that the NodeID change makes the code incompatible with old simulation snapshots. * whisper/whisperv5, whisper/whisperv6: port to p2p/enode This port was easy because whisper uses []byte for node IDs and URL strings in the API. * eth: port to p2p/enode Again, easy to port because eth uses strings for node IDs and doesn't care about node information in any way. * les: port to p2p/enode Apart from replacing discover.NodeID with enode.ID, most changes are in the server pool code. It now deals with complete nodes instead of (Pubkey, IP, Port) triples. The database format is unchanged for now, but we should probably change it to use the node database later. * node: port to p2p/enode This change simply replaces discover.Node and discover.NodeID with their new equivalents. * swarm/network: port to p2p/enode Swarm has its own node address representation, BzzAddr, containing both an overlay address (the hash of a secp256k1 public key) and an underlay address (enode:// URL). There are no changes to the BzzAddr format in this commit, but certain operations such as creating a BzzAddr from a node ID are now impossible because node IDs aren't public keys anymore. Most swarm-related changes in the series remove uses of NewAddrFromNodeID, replacing it with NewAddr which takes a complete node as argument. ToOverlayAddr is removed because we can just use the node ID directly.
2018-09-24 22:59:00 +00:00
nodeID enode.ID
2018-06-20 12:06:27 +00:00
}
// check represents a reference to a file that is retrieved
// from a particular node.
type check struct {
key string
all: new p2p node representation (#17643) Package p2p/enode provides a generalized representation of p2p nodes which can contain arbitrary information in key/value pairs. It is also the new home for the node database. The "v4" identity scheme is also moved here from p2p/enr to remove the dependency on Ethereum crypto from that package. Record signature handling is changed significantly. The identity scheme registry is removed and acceptable schemes must be passed to any method that needs identity. This means records must now be validated explicitly after decoding. The enode API is designed to make signature handling easy and safe: most APIs around the codebase work with enode.Node, which is a wrapper around a valid record. Going from enr.Record to enode.Node requires a valid signature. * p2p/discover: port to p2p/enode This ports the discovery code to the new node representation in p2p/enode. The wire protocol is unchanged, this can be considered a refactoring change. The Kademlia table can now deal with nodes using an arbitrary identity scheme. This requires a few incompatible API changes: - Table.Lookup is not available anymore. It used to take a public key as argument because v4 protocol requires one. Its replacement is LookupRandom. - Table.Resolve takes *enode.Node instead of NodeID. This is also for v4 protocol compatibility because nodes cannot be looked up by ID alone. - Types Node and NodeID are gone. Further commits in the series will be fixes all over the the codebase to deal with those removals. * p2p: port to p2p/enode and discovery changes This adapts package p2p to the changes in p2p/discover. All uses of discover.Node and discover.NodeID are replaced by their equivalents from p2p/enode. New API is added to retrieve the enode.Node instance of a peer. The behavior of Server.Self with discovery disabled is improved. It now tries much harder to report a working IP address, falling back to 127.0.0.1 if no suitable address can be determined through other means. These changes were needed for tests of other packages later in the series. * p2p/simulations, p2p/testing: port to p2p/enode No surprises here, mostly replacements of discover.Node, discover.NodeID with their new equivalents. The 'interesting' API changes are: - testing.ProtocolSession tracks complete nodes, not just their IDs. - adapters.NodeConfig has a new method to create a complete node. These changes were needed to make swarm tests work. Note that the NodeID change makes the code incompatible with old simulation snapshots. * whisper/whisperv5, whisper/whisperv6: port to p2p/enode This port was easy because whisper uses []byte for node IDs and URL strings in the API. * eth: port to p2p/enode Again, easy to port because eth uses strings for node IDs and doesn't care about node information in any way. * les: port to p2p/enode Apart from replacing discover.NodeID with enode.ID, most changes are in the server pool code. It now deals with complete nodes instead of (Pubkey, IP, Port) triples. The database format is unchanged for now, but we should probably change it to use the node database later. * node: port to p2p/enode This change simply replaces discover.Node and discover.NodeID with their new equivalents. * swarm/network: port to p2p/enode Swarm has its own node address representation, BzzAddr, containing both an overlay address (the hash of a secp256k1 public key) and an underlay address (enode:// URL). There are no changes to the BzzAddr format in this commit, but certain operations such as creating a BzzAddr from a node ID are now impossible because node IDs aren't public keys anymore. Most swarm-related changes in the series remove uses of NewAddrFromNodeID, replacing it with NewAddr which takes a complete node as argument. ToOverlayAddr is removed because we can just use the node ID directly.
2018-09-24 22:59:00 +00:00
nodeID enode.ID
2018-06-20 12:06:27 +00:00
}
// testSwarmNetwork is a helper function used for testing different
// static and dynamic Swarm network simulations.
// It is responsible for:
// - Setting up a Swarm network simulation, and updates the number of nodes within the network on every step according to steps.
// - Uploading a unique file to every node on every step.
// - 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) {
Ci race detector handle failing tests (#19143) * swarm/storage: increase mget timeout in common_test.go TestDbStoreCorrect_1k sometimes timed out with -race on Travis. --- FAIL: TestDbStoreCorrect_1k (24.63s) common_test.go:194: testStore failed: timed out after 10s * swarm: remove unused vars from TestSnapshotSyncWithServer nodeCount and chunkCount is returned from setupSim and those values we use. * swarm: move race/norace helpers from stream to testutil As we will need to use the flag in other packages, too. * swarm: refactor TestSwarmNetwork case Extract long running test cases for better visibility. * swarm/network: skip TestSyncingViaGlobalSync with -race As panics on Travis. panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7e351b] * swarm: run TestSwarmNetwork with fewer nodes with -race As otherwise we always get test failure with `network_test.go:374: context deadline exceeded` even with raised `Timeout`. * swarm/network: run TestDeliveryFromNodes with fewer nodes with -race Test on Travis times out with 8 or more nodes if -race flag is present. * swarm/network: smaller node count for discovery tests with -race TestDiscoveryPersistenceSimulationSimAdapters failed on Travis with `-race` flag present. The failure was due to extensive memory usage, coming from the CGO runtime. Using a smaller node count resolves the issue. === RUN TestDiscoveryPersistenceSimulationSimAdapter ==7227==ERROR: ThreadSanitizer failed to allocate 0x80000 (524288) bytes of clock allocator (error code: 12) FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6976 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) FAIL github.com/ethereum/go-ethereum/swarm/network/simulations/discovery 804.826s * swarm/network: run TestFileRetrieval with fewer nodes with -race Otherwise we get a failure due to extensive memory usage, as the CGO runtime cannot allocate more bytes. === RUN TestFileRetrieval ==7366==ERROR: ThreadSanitizer failed to allocate 0x80000 (524288) bytes of clock allocator (error code: 12) FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6976 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) FAIL github.com/ethereum/go-ethereum/swarm/network/stream 155.165s * swarm/network: run TestRetrieval with fewer nodes with -race Otherwise we get a failure due to extensive memory usage, as the CGO runtime cannot allocate more bytes ("ThreadSanitizer failed to allocate"). * swarm/network: skip flaky TestGetSubscriptionsRPC on Travis w/ -race Test fails a lot with something like: streamer_test.go:1332: Real subscriptions and expected amount don't match; real: 0, expected: 20 * swarm/storage: skip TestDB_SubscribePull* tests on Travis w/ -race Travis just hangs... ok github.com/ethereum/go-ethereum/swarm/storage/feed/lookup 1.307s keepalive keepalive keepalive or panics after a while. Without these tests the race detector job is now stable. Let's invetigate these tests in a separate issue: https://github.com/ethersphere/go-ethereum/issues/1245
2019-02-20 21:57:42 +00:00
t.Helper()
2018-06-20 12:06:27 +00:00
if o == nil {
o = new(testSwarmNetworkOptions)
}
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
sim := simulation.New(map[string]simulation.ServiceFunc{
"swarm": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
2018-06-20 12:06:27 +00:00
config := api.NewConfig()
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
dir, err := ioutil.TempDir("", "swarm-network-test-node")
2018-06-20 12:06:27 +00:00
if err != nil {
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
return nil, nil, err
}
cleanup = func() {
err := os.RemoveAll(dir)
if err != nil {
log.Error("cleaning up swarm temp dir", "err", err)
}
2018-06-20 12:06:27 +00:00
}
config.Path = dir
privkey, err := crypto.GenerateKey()
if err != nil {
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
return nil, cleanup, err
2018-06-20 12:06:27 +00:00
}
nodekey, err := crypto.GenerateKey()
if err != nil {
return nil, cleanup, err
}
2018-06-20 12:06:27 +00:00
config.Init(privkey, nodekey)
2018-06-20 12:06:27 +00:00
config.DeliverySkipCheck = o.SkipCheck
config.Port = ""
2018-06-20 12:06:27 +00:00
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
swarm, err := NewSwarm(config, nil)
2018-06-20 12:06:27 +00:00
if err != nil {
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
return nil, cleanup, err
2018-06-20 12:06:27 +00:00
}
bucket.Store(simulation.BucketKeyKademlia, swarm.bzz.Hive.Kademlia)
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
log.Info("new swarm", "bzzKey", config.BzzKey, "baseAddr", fmt.Sprintf("%x", swarm.bzz.BaseAddr()))
return swarm, cleanup, nil
2018-06-20 12:06:27 +00:00
},
})
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
defer sim.Close()
2018-06-20 12:06:27 +00:00
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
ctx := context.Background()
if o.Timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, o.Timeout)
defer cancel()
}
2018-06-20 12:06:27 +00:00
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
files := make([]file, 0)
2018-06-20 12:06:27 +00:00
for i, step := range steps {
log.Debug("test sync step", "n", i+1, "nodes", step.nodeCount)
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
change := step.nodeCount - len(sim.UpNodeIDs())
2018-06-20 12:06:27 +00:00
if change > 0 {
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
_, err := sim.AddNodesAndConnectChain(change)
2018-06-20 12:06:27 +00:00
if err != nil {
t.Fatal(err)
}
} else if change < 0 {
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
_, err := sim.StopRandomNodes(-change)
2018-06-20 12:06:27 +00:00
if err != nil {
t.Fatal(err)
}
} else {
t.Logf("step %v: no change in nodes", i)
continue
}
var checkStatusM sync.Map
var nodeStatusM sync.Map
var totalFoundCount uint64
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) error {
nodeIDs := sim.UpNodeIDs()
rand.Shuffle(len(nodeIDs), func(i, j int) {
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
nodeIDs[i], nodeIDs[j] = nodeIDs[j], nodeIDs[i]
})
for _, id := range nodeIDs {
key, data, err := uploadFile(sim.Service("swarm", id).(*Swarm))
if err != nil {
return err
2018-06-20 12:06:27 +00:00
}
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
log.Trace("file uploaded", "node", id, "key", key.String())
files = append(files, file{
addr: key,
data: data,
nodeID: id,
})
}
2018-06-20 12:06:27 +00:00
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
if *waitKademlia {
if _, err := sim.WaitTillHealthy(ctx); err != nil {
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
return err
2018-06-20 12:06:27 +00:00
}
}
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
// File retrieval check is repeated until all uploaded files are retrieved from all nodes
// or until the timeout is reached.
for {
if retrieve(sim, files, &checkStatusM, &nodeStatusM, &totalFoundCount) == 0 {
return nil
}
2018-06-20 12:06:27 +00:00
}
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
})
2018-06-20 12:06:27 +00:00
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
if result.Error != nil {
t.Fatal(result.Error)
2018-06-20 12:06:27 +00:00
}
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
log.Debug("done: test sync step", "n", i+1, "nodes", step.nodeCount)
2018-06-20 12:06:27 +00:00
}
}
// uploadFile, uploads a short file to the swarm instance
// using the api.Put method.
func uploadFile(swarm *Swarm) (storage.Address, string, error) {
b := make([]byte, 8)
_, err := rand.Read(b)
if err != nil {
return nil, "", err
}
// File data is very short, but it is ensured that its
// uniqueness is very certain.
data := fmt.Sprintf("test content %s %x", time.Now().Round(0), b)
ctx := context.TODO()
k, wait, err := swarm.api.Put(ctx, data, "text/plain", false)
2018-06-20 12:06:27 +00:00
if err != nil {
return nil, "", err
}
if wait != nil {
err = wait(ctx)
2018-06-20 12:06:27 +00:00
}
return k, data, err
2018-06-20 12:06:27 +00:00
}
// retrieve is the function that is used for checking the availability of
// uploaded files in testSwarmNetwork test helper function.
func retrieve(
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
sim *simulation.Simulation,
2018-06-20 12:06:27 +00:00
files []file,
checkStatusM *sync.Map,
nodeStatusM *sync.Map,
totalFoundCount *uint64,
) (missing uint64) {
rand.Shuffle(len(files), func(i, j int) {
2018-06-20 12:06:27 +00:00
files[i], files[j] = files[j], files[i]
})
var totalWg sync.WaitGroup
errc := make(chan error)
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
nodeIDs := sim.UpNodeIDs()
2018-06-20 12:06:27 +00:00
totalCheckCount := len(nodeIDs) * len(files)
for _, id := range nodeIDs {
if _, ok := nodeStatusM.Load(id); ok {
continue
}
start := time.Now()
var checkCount uint64
var foundCount uint64
totalWg.Add(1)
var wg sync.WaitGroup
swarm: network simulation for swarm tests (#769) * cmd/swarm: minor cli flag text adjustments * cmd/swarm, swarm/storage, swarm: fix mingw on windows test issues * cmd/swarm: support for smoke tests on the production swarm cluster * cmd/swarm/swarm-smoke: simplify cluster logic as per suggestion * changed colour of landing page * landing page reacts to enter keypress * swarm/api/http: sticky footer for swarm landing page using flex * swarm/api/http: sticky footer for error pages and fix for multiple choices * swarm: propagate ctx to internal apis (#754) * swarm/simnet: add basic node/service functions * swarm/netsim: add buckets for global state and kademlia health check * swarm/netsim: Use sync.Map as bucket and provide cleanup function for... * swarm, swarm/netsim: adjust SwarmNetworkTest * swarm/netsim: fix tests * swarm: added visualization option to sim net redesign * swarm/netsim: support multiple services per node * swarm/netsim: remove redundant return statement * swarm/netsim: add comments * swarm: shutdown HTTP in Simulation.Close * swarm: sim HTTP server timeout * swarm/netsim: add more simulation methods and peer events examples * swarm/netsim: add WaitKademlia example * swarm/netsim: fix comments * swarm/netsim: terminate peer events goroutines on simulation done * swarm, swarm/netsim: naming updates * swarm/netsim: return not healthy kademlias on WaitTillHealthy * swarm: fix WaitTillHealthy call in testSwarmNetwork * swarm/netsim: allow bucket to have any type for a key * swarm: Added snapshots to new netsim * swarm/netsim: add more tests for bucket * swarm/netsim: move http related things into separate files * swarm/netsim: add AddNodeWithService option * swarm/netsim: add more tests and Start* methods * swarm/netsim: add peer events and kademlia tests * swarm/netsim: fix some tests flakiness * swarm/netsim: improve random nodes selection, fix TestStartStop* tests * swarm/netsim: remove time measurement from TestClose to avoid flakiness * swarm/netsim: builder pattern for netsim HTTP server (#773) * swarm/netsim: add connect related tests * swarm/netsim: add comment for TestPeerEvents * swarm: rename netsim package to network/simulation
2018-07-17 05:08:34 +00:00
swarm := sim.Service("swarm", id).(*Swarm)
2018-06-20 12:06:27 +00:00
for _, f := range files {
checkKey := check{
key: f.addr.String(),
nodeID: id,
}
if n, ok := checkStatusM.Load(checkKey); ok && n.(int) == 0 {
continue
}
checkCount++
wg.Add(1)
all: new p2p node representation (#17643) Package p2p/enode provides a generalized representation of p2p nodes which can contain arbitrary information in key/value pairs. It is also the new home for the node database. The "v4" identity scheme is also moved here from p2p/enr to remove the dependency on Ethereum crypto from that package. Record signature handling is changed significantly. The identity scheme registry is removed and acceptable schemes must be passed to any method that needs identity. This means records must now be validated explicitly after decoding. The enode API is designed to make signature handling easy and safe: most APIs around the codebase work with enode.Node, which is a wrapper around a valid record. Going from enr.Record to enode.Node requires a valid signature. * p2p/discover: port to p2p/enode This ports the discovery code to the new node representation in p2p/enode. The wire protocol is unchanged, this can be considered a refactoring change. The Kademlia table can now deal with nodes using an arbitrary identity scheme. This requires a few incompatible API changes: - Table.Lookup is not available anymore. It used to take a public key as argument because v4 protocol requires one. Its replacement is LookupRandom. - Table.Resolve takes *enode.Node instead of NodeID. This is also for v4 protocol compatibility because nodes cannot be looked up by ID alone. - Types Node and NodeID are gone. Further commits in the series will be fixes all over the the codebase to deal with those removals. * p2p: port to p2p/enode and discovery changes This adapts package p2p to the changes in p2p/discover. All uses of discover.Node and discover.NodeID are replaced by their equivalents from p2p/enode. New API is added to retrieve the enode.Node instance of a peer. The behavior of Server.Self with discovery disabled is improved. It now tries much harder to report a working IP address, falling back to 127.0.0.1 if no suitable address can be determined through other means. These changes were needed for tests of other packages later in the series. * p2p/simulations, p2p/testing: port to p2p/enode No surprises here, mostly replacements of discover.Node, discover.NodeID with their new equivalents. The 'interesting' API changes are: - testing.ProtocolSession tracks complete nodes, not just their IDs. - adapters.NodeConfig has a new method to create a complete node. These changes were needed to make swarm tests work. Note that the NodeID change makes the code incompatible with old simulation snapshots. * whisper/whisperv5, whisper/whisperv6: port to p2p/enode This port was easy because whisper uses []byte for node IDs and URL strings in the API. * eth: port to p2p/enode Again, easy to port because eth uses strings for node IDs and doesn't care about node information in any way. * les: port to p2p/enode Apart from replacing discover.NodeID with enode.ID, most changes are in the server pool code. It now deals with complete nodes instead of (Pubkey, IP, Port) triples. The database format is unchanged for now, but we should probably change it to use the node database later. * node: port to p2p/enode This change simply replaces discover.Node and discover.NodeID with their new equivalents. * swarm/network: port to p2p/enode Swarm has its own node address representation, BzzAddr, containing both an overlay address (the hash of a secp256k1 public key) and an underlay address (enode:// URL). There are no changes to the BzzAddr format in this commit, but certain operations such as creating a BzzAddr from a node ID are now impossible because node IDs aren't public keys anymore. Most swarm-related changes in the series remove uses of NewAddrFromNodeID, replacing it with NewAddr which takes a complete node as argument. ToOverlayAddr is removed because we can just use the node ID directly.
2018-09-24 22:59:00 +00:00
go func(f file, id enode.ID) {
2018-06-20 12:06:27 +00:00
defer wg.Done()
log.Debug("api get: check file", "node", id.String(), "key", f.addr.String(), "total files found", atomic.LoadUint64(totalFoundCount))
r, _, _, _, err := swarm.api.Get(context.TODO(), api.NOOPDecrypt, f.addr, "/")
2018-06-20 12:06:27 +00:00
if err != nil {
errc <- fmt.Errorf("api get: node %s, key %s, kademlia %s: %v", id, f.addr, swarm.bzz.Hive, err)
return
}
d, err := ioutil.ReadAll(r)
if err != nil {
errc <- fmt.Errorf("api get: read response: node %s, key %s: kademlia %s: %v", id, f.addr, swarm.bzz.Hive, err)
return
}
data := string(d)
if data != f.data {
errc <- fmt.Errorf("file contend missmatch: node %s, key %s, expected %q, got %q", id, f.addr, f.data, data)
return
}
checkStatusM.Store(checkKey, 0)
atomic.AddUint64(&foundCount, 1)
log.Info("api get: file found", "node", id.String(), "key", f.addr.String(), "content", data, "files found", atomic.LoadUint64(&foundCount))
}(f, id)
}
all: new p2p node representation (#17643) Package p2p/enode provides a generalized representation of p2p nodes which can contain arbitrary information in key/value pairs. It is also the new home for the node database. The "v4" identity scheme is also moved here from p2p/enr to remove the dependency on Ethereum crypto from that package. Record signature handling is changed significantly. The identity scheme registry is removed and acceptable schemes must be passed to any method that needs identity. This means records must now be validated explicitly after decoding. The enode API is designed to make signature handling easy and safe: most APIs around the codebase work with enode.Node, which is a wrapper around a valid record. Going from enr.Record to enode.Node requires a valid signature. * p2p/discover: port to p2p/enode This ports the discovery code to the new node representation in p2p/enode. The wire protocol is unchanged, this can be considered a refactoring change. The Kademlia table can now deal with nodes using an arbitrary identity scheme. This requires a few incompatible API changes: - Table.Lookup is not available anymore. It used to take a public key as argument because v4 protocol requires one. Its replacement is LookupRandom. - Table.Resolve takes *enode.Node instead of NodeID. This is also for v4 protocol compatibility because nodes cannot be looked up by ID alone. - Types Node and NodeID are gone. Further commits in the series will be fixes all over the the codebase to deal with those removals. * p2p: port to p2p/enode and discovery changes This adapts package p2p to the changes in p2p/discover. All uses of discover.Node and discover.NodeID are replaced by their equivalents from p2p/enode. New API is added to retrieve the enode.Node instance of a peer. The behavior of Server.Self with discovery disabled is improved. It now tries much harder to report a working IP address, falling back to 127.0.0.1 if no suitable address can be determined through other means. These changes were needed for tests of other packages later in the series. * p2p/simulations, p2p/testing: port to p2p/enode No surprises here, mostly replacements of discover.Node, discover.NodeID with their new equivalents. The 'interesting' API changes are: - testing.ProtocolSession tracks complete nodes, not just their IDs. - adapters.NodeConfig has a new method to create a complete node. These changes were needed to make swarm tests work. Note that the NodeID change makes the code incompatible with old simulation snapshots. * whisper/whisperv5, whisper/whisperv6: port to p2p/enode This port was easy because whisper uses []byte for node IDs and URL strings in the API. * eth: port to p2p/enode Again, easy to port because eth uses strings for node IDs and doesn't care about node information in any way. * les: port to p2p/enode Apart from replacing discover.NodeID with enode.ID, most changes are in the server pool code. It now deals with complete nodes instead of (Pubkey, IP, Port) triples. The database format is unchanged for now, but we should probably change it to use the node database later. * node: port to p2p/enode This change simply replaces discover.Node and discover.NodeID with their new equivalents. * swarm/network: port to p2p/enode Swarm has its own node address representation, BzzAddr, containing both an overlay address (the hash of a secp256k1 public key) and an underlay address (enode:// URL). There are no changes to the BzzAddr format in this commit, but certain operations such as creating a BzzAddr from a node ID are now impossible because node IDs aren't public keys anymore. Most swarm-related changes in the series remove uses of NewAddrFromNodeID, replacing it with NewAddr which takes a complete node as argument. ToOverlayAddr is removed because we can just use the node ID directly.
2018-09-24 22:59:00 +00:00
go func(id enode.ID) {
2018-06-20 12:06:27 +00:00
defer totalWg.Done()
wg.Wait()
atomic.AddUint64(totalFoundCount, foundCount)
if foundCount == checkCount {
log.Info("all files are found for node", "id", id.String(), "duration", time.Since(start))
nodeStatusM.Store(id, 0)
return
}
log.Debug("files missing for node", "id", id.String(), "check", checkCount, "found", foundCount)
}(id)
}
go func() {
totalWg.Wait()
close(errc)
}()
var errCount int
for err := range errc {
if err != nil {
errCount++
}
log.Warn(err.Error())
}
log.Info("check stats", "total check count", totalCheckCount, "total files found", atomic.LoadUint64(totalFoundCount), "total errors", errCount)
return uint64(totalCheckCount) - atomic.LoadUint64(totalFoundCount)
}