swarm/network/stream: correctly use Simulation.Run callback

https://github.com/ethersphere/go-ethereum/issues/1198#issuecomment-461783804
This commit is contained in:
Janos Guljas 2019-02-08 13:22:35 +01:00
parent 91f87355a2
commit 11d944121f
5 changed files with 16 additions and 21 deletions

View file

@ -589,7 +589,7 @@ func testDeliveryFromNodes(t *testing.T, nodes, chunkCount int, skipCheck bool)
return fmt.Errorf("Test failed, chunks not available on all nodes") return fmt.Errorf("Test failed, chunks not available on all nodes")
} }
if err := <-retErrC; err != nil { if err := <-retErrC; err != nil {
t.Fatalf("requesting chunks: %v", err) return fmt.Errorf("requesting chunks: %v", err)
} }
log.Debug("Test terminated successfully") log.Debug("Test terminated successfully")
return nil return nil
@ -664,14 +664,14 @@ func benchmarkDeliveryFromNodes(b *testing.B, nodes, chunkCount int, skipCheck b
item, ok := sim.NodeItem(node, bucketKeyFileStore) item, ok := sim.NodeItem(node, bucketKeyFileStore)
if !ok { if !ok {
b.Fatal("No filestore") return errors.New("No filestore")
} }
remoteFileStore := item.(*storage.FileStore) remoteFileStore := item.(*storage.FileStore)
pivotNode := nodeIDs[0] pivotNode := nodeIDs[0]
item, ok = sim.NodeItem(pivotNode, bucketKeyNetStore) item, ok = sim.NodeItem(pivotNode, bucketKeyNetStore)
if !ok { if !ok {
b.Fatal("No filestore") return errors.New("No filestore")
} }
netStore := item.(*storage.NetStore) netStore := item.(*storage.NetStore)
@ -713,12 +713,12 @@ func benchmarkDeliveryFromNodes(b *testing.B, nodes, chunkCount int, skipCheck b
ctx := context.TODO() ctx := context.TODO()
hash, wait, err := remoteFileStore.Store(ctx, testutil.RandomReader(i, chunkSize), int64(chunkSize), false) hash, wait, err := remoteFileStore.Store(ctx, testutil.RandomReader(i, chunkSize), int64(chunkSize), false)
if err != nil { if err != nil {
b.Fatalf("expected no error. got %v", err) return fmt.Errorf("store: %v", err)
} }
// wait until all chunks stored // wait until all chunks stored
err = wait(ctx) err = wait(ctx)
if err != nil { if err != nil {
b.Fatalf("expected no error. got %v", err) return fmt.Errorf("wait store: %v", err)
} }
// collect the hashes // collect the hashes
hashes[i] = hash hashes[i] = hash
@ -754,10 +754,7 @@ func benchmarkDeliveryFromNodes(b *testing.B, nodes, chunkCount int, skipCheck b
break Loop break Loop
} }
} }
if err != nil { return err
b.Fatal(err)
}
return nil
}) })
if result.Error != nil { if result.Error != nil {
b.Fatal(result.Error) b.Fatal(result.Error)

View file

@ -118,13 +118,11 @@ func testIntervals(t *testing.T, live bool, history *Range, skipCheck bool) {
_, wait, err := fileStore.Store(ctx, testutil.RandomReader(1, size), int64(size), false) _, wait, err := fileStore.Store(ctx, testutil.RandomReader(1, size), int64(size), false)
if err != nil { if err != nil {
log.Error("Store error: %v", "err", err) return fmt.Errorf("store: %v", err)
t.Fatal(err)
} }
err = wait(ctx) err = wait(ctx)
if err != nil { if err != nil {
log.Error("Wait error: %v", "err", err) return fmt.Errorf("wait store: %v", err)
t.Fatal(err)
} }
item, ok = sim.NodeItem(checker, bucketKeyRegistry) item, ok = sim.NodeItem(checker, bucketKeyRegistry)

View file

@ -1290,7 +1290,7 @@ func TestGetSubscriptionsRPC(t *testing.T) {
select { select {
case <-allSubscriptionsDone: case <-allSubscriptionsDone:
case <-ctx.Done(): case <-ctx.Done():
t.Fatal("Context timed out") return errors.New("Context timed out")
} }
lock.RLock() lock.RLock()
@ -1302,14 +1302,14 @@ func TestGetSubscriptionsRPC(t *testing.T) {
//create rpc client //create rpc client
client, err := node.Client() client, err := node.Client()
if err != nil { if err != nil {
t.Fatalf("create node 1 rpc client fail: %v", err) return fmt.Errorf("create node 1 rpc client fail: %v", err)
} }
//ask it for subscriptions //ask it for subscriptions
pstreams := make(map[string][]string) pstreams := make(map[string][]string)
err = client.Call(&pstreams, "stream_getPeerSubscriptions") err = client.Call(&pstreams, "stream_getPeerSubscriptions")
if err != nil { if err != nil {
t.Fatal(err) return fmt.Errorf("client call stream_getPeerSubscriptions: %v", err)
} }
//length of the subscriptions can not be smaller than number of peers //length of the subscriptions can not be smaller than number of peers
log.Debug("node subscriptions", "node", node.String()) log.Debug("node subscriptions", "node", node.String())

View file

@ -142,7 +142,7 @@ func testSyncBetweenNodes(t *testing.T, nodes, chunkCount int, skipCheck bool, p
id := nodeIDs[j] id := nodeIDs[j]
client, err := sim.Net.GetNode(id).Client() client, err := sim.Net.GetNode(id).Client()
if err != nil { if err != nil {
t.Fatal(err) return fmt.Errorf("node %s client: %v", id, err)
} }
sid := nodeIDs[j+1] sid := nodeIDs[j+1]
client.CallContext(ctx, nil, "stream_subscribeStream", sid, NewStream("SYNC", FormatSyncBinKey(1), false), NewRange(0, 0), Top) client.CallContext(ctx, nil, "stream_subscribeStream", sid, NewStream("SYNC", FormatSyncBinKey(1), false), NewRange(0, 0), Top)
@ -158,7 +158,7 @@ func testSyncBetweenNodes(t *testing.T, nodes, chunkCount int, skipCheck bool, p
size := chunkCount * chunkSize size := chunkCount * chunkSize
_, wait, err := fileStore.Store(ctx, testutil.RandomReader(j, size), int64(size), false) _, wait, err := fileStore.Store(ctx, testutil.RandomReader(j, size), int64(size), false)
if err != nil { if err != nil {
t.Fatal(err.Error()) return fmt.Errorf("fileStore.Store: %v", err)
} }
wait(ctx) wait(ctx)
} }
@ -273,7 +273,7 @@ func TestSameVersionID(t *testing.T) {
//the peers should connect, thus getting the peer should not return nil //the peers should connect, thus getting the peer should not return nil
if registry.getPeer(nodes[1]) == nil { if registry.getPeer(nodes[1]) == nil {
t.Fatal("Expected the peer to not be nil, but it is") return errors.New("Expected the peer to not be nil, but it is")
} }
return nil return nil
}) })
@ -338,7 +338,7 @@ func TestDifferentVersionID(t *testing.T) {
//getting the other peer should fail due to the different version numbers //getting the other peer should fail due to the different version numbers
if registry.getPeer(nodes[1]) != nil { if registry.getPeer(nodes[1]) != nil {
t.Fatal("Expected the peer to be nil, but it is not") return errors.New("Expected the peer to be nil, but it is not")
} }
return nil return nil
}) })

View file

@ -114,7 +114,7 @@ func TestNonExistingHashesWithServer(t *testing.T) {
id := sim.Net.GetRandomUpNode().ID() id := sim.Net.GetRandomUpNode().ID()
item, ok := sim.NodeItem(id, bucketKeyFileStore) item, ok := sim.NodeItem(id, bucketKeyFileStore)
if !ok { if !ok {
t.Fatalf("No filestore") return errors.New("No filestore")
} }
fileStore := item.(*storage.FileStore) fileStore := item.(*storage.FileStore)
//create a bogus hash //create a bogus hash