mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
swarm/network: expose simulation RandomUpNode to use in stream tests
This commit is contained in:
parent
b7c333faa6
commit
bc42faee0a
6 changed files with 23 additions and 31 deletions
|
|
@ -54,7 +54,7 @@ func (s *Simulation) ConnectToLastNode(id discover.NodeID) (err error) {
|
|||
// ConnectToRandomNode connects the node with provieded NodeID
|
||||
// to a random node that is up.
|
||||
func (s *Simulation) ConnectToRandomNode(id discover.NodeID) (err error) {
|
||||
n := s.randomUpNode(id)
|
||||
n := s.RandomUpNode(id)
|
||||
if n == nil {
|
||||
return ErrNodeNotFound
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ func (s *Simulation) StopNode(id discover.NodeID) (err error) {
|
|||
|
||||
// StopRandomNode stops a random node.
|
||||
func (s *Simulation) StopRandomNode() (id discover.NodeID, err error) {
|
||||
n := s.randomUpNode()
|
||||
n := s.RandomUpNode()
|
||||
if n == nil {
|
||||
return id, ErrNodeNotFound
|
||||
}
|
||||
|
|
@ -324,18 +324,18 @@ func init() {
|
|||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
// randomUpNode returns a random SimNode that is up.
|
||||
// RandomUpNode returns a random SimNode that is up.
|
||||
// Arguments are NodeIDs for nodes that should not be returned.
|
||||
func (s *Simulation) randomUpNode(exclude ...discover.NodeID) *adapters.SimNode {
|
||||
func (s *Simulation) RandomUpNode(exclude ...discover.NodeID) *adapters.SimNode {
|
||||
return s.randomNode(s.UpNodeIDs(), exclude...)
|
||||
}
|
||||
|
||||
// randomUpNode returns a random SimNode that is not up.
|
||||
// randomDownNode returns a random SimNode that is not up.
|
||||
func (s *Simulation) randomDownNode(exclude ...discover.NodeID) *adapters.SimNode {
|
||||
return s.randomNode(s.DownNodeIDs(), exclude...)
|
||||
}
|
||||
|
||||
// randomUpNode returns a random SimNode from the slice of NodeIDs.
|
||||
// randomNode returns a random SimNode from the slice of NodeIDs.
|
||||
func (s *Simulation) randomNode(ids []discover.NodeID, exclude ...discover.NodeID) *adapters.SimNode {
|
||||
for _, e := range exclude {
|
||||
var i int
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ func (s *Simulation) Service(name string, id discover.NodeID) node.Service {
|
|||
// RandomService returns a single Service by name on a
|
||||
// randomly chosen node that is up.
|
||||
func (s *Simulation) RandomService(name string) node.Service {
|
||||
n := s.randomUpNode()
|
||||
n := s.RandomUpNode()
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -384,6 +384,10 @@ func uploadFilesToNodes(sim *simulation.Simulation) ([]storage.Address, []string
|
|||
return rootAddrs, rfiles, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
//generate a random file (string)
|
||||
func generateRandomFile() (string, error) {
|
||||
//generate a random file size between minFileSize and maxFileSize
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package stream
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
|
|
@ -343,17 +342,15 @@ func runRetrievalTest(chunkCount int, nodeCount int) error {
|
|||
//uploadFinished := make(chan struct{})
|
||||
//channel to trigger new node checks
|
||||
|
||||
//select one index at random...
|
||||
idx := rand.Intn(len(nodeIDs))
|
||||
//...and get the the node at that index
|
||||
//get the the node at that index
|
||||
//this is the node selected for upload
|
||||
node := nodeIDs[idx]
|
||||
item, ok := sim.NodeItem(node, bucketKeyStore)
|
||||
node := sim.RandomUpNode()
|
||||
item, ok := sim.NodeItem(node.ID, bucketKeyStore)
|
||||
if !ok {
|
||||
return fmt.Errorf("No localstore")
|
||||
}
|
||||
lstore := item.(*storage.LocalStore)
|
||||
conf.hashes, err = uploadFileToSingleNodeStore(node, chunkCount, lstore)
|
||||
conf.hashes, err = uploadFileToSingleNodeStore(node.ID, chunkCount, lstore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import (
|
|||
crand "crypto/rand"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
|
|
@ -56,10 +55,6 @@ type synctestConfig struct {
|
|||
addrToIdMap map[string]discover.NodeID
|
||||
}
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
}
|
||||
|
||||
//This test is a syncing test for nodes.
|
||||
//One node is randomly selected to be the pivot node.
|
||||
//A configurable number of chunks and nodes can be
|
||||
|
|
@ -191,17 +186,15 @@ func testSyncing(t *testing.T, chunkCount int, nodeCount int) {
|
|||
conf.addrToIdMap[string(a)] = n
|
||||
}
|
||||
|
||||
//select one index at random...
|
||||
idx := rand.Intn(len(nodeIDs))
|
||||
//...and get the the node at that index
|
||||
//get the the node at that index
|
||||
//this is the node selected for upload
|
||||
node := nodeIDs[idx]
|
||||
item, ok := sim.NodeItem(node, bucketKeyStore)
|
||||
node := sim.RandomUpNode()
|
||||
item, ok := sim.NodeItem(node.ID, bucketKeyStore)
|
||||
if !ok {
|
||||
return fmt.Errorf("No localstore")
|
||||
}
|
||||
lstore := item.(*storage.LocalStore)
|
||||
hashes, err := uploadFileToSingleNodeStore(node, chunkCount, lstore)
|
||||
hashes, err := uploadFileToSingleNodeStore(node.ID, chunkCount, lstore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -403,17 +396,15 @@ func runSyncTest(chunkCount int, nodeCount int) error {
|
|||
}
|
||||
}
|
||||
}()
|
||||
//select one index at random...
|
||||
idx := rand.Intn(len(nodeIDs))
|
||||
//...and get the the node at that index
|
||||
//get the the node at that index
|
||||
//this is the node selected for upload
|
||||
node := nodeIDs[idx]
|
||||
item, ok := sim.NodeItem(node, bucketKeyStore)
|
||||
node := sim.RandomUpNode()
|
||||
item, ok := sim.NodeItem(node.ID, bucketKeyStore)
|
||||
if !ok {
|
||||
return fmt.Errorf("No localstore")
|
||||
}
|
||||
lstore := item.(*storage.LocalStore)
|
||||
hashes, err := uploadFileToSingleNodeStore(node, chunkCount, lstore)
|
||||
hashes, err := uploadFileToSingleNodeStore(node.ID, chunkCount, lstore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue