@@ -19,9 +19,11 @@ package stream
1919import (
2020 "bytes"
2121 "context"
22+ "errors"
2223 "fmt"
2324 "os"
2425 "sync"
26+ "sync/atomic"
2527 "testing"
2628 "time"
2729
@@ -500,7 +502,7 @@ func testDeliveryFromNodes(t *testing.T, nodes, chunkCount int, skipCheck bool)
500502
501503 log .Info ("Starting simulation" )
502504 ctx := context .Background ()
503- result := sim .Run (ctx , func (ctx context.Context , sim * simulation.Simulation ) error {
505+ result := sim .Run (ctx , func (ctx context.Context , sim * simulation.Simulation ) ( err error ) {
504506 nodeIDs := sim .UpNodeIDs ()
505507 //determine the pivot node to be the first node of the simulation
506508 pivot := nodeIDs [0 ]
@@ -553,14 +555,13 @@ func testDeliveryFromNodes(t *testing.T, nodes, chunkCount int, skipCheck bool)
553555 }
554556 pivotFileStore := item .(* storage.FileStore )
555557 log .Debug ("Starting retrieval routine" )
558+ retErrC := make (chan error )
556559 go func () {
557560 // start the retrieval on the pivot node - this will spawn retrieve requests for missing chunks
558561 // we must wait for the peer connections to have started before requesting
559562 n , err := readAll (pivotFileStore , fileHash )
560563 log .Info (fmt .Sprintf ("retrieved %v" , fileHash ), "read" , n , "err" , err )
561- if err != nil {
562- t .Fatalf ("requesting chunks action error: %v" , err )
563- }
564+ retErrC <- err
564565 }()
565566
566567 log .Debug ("Watching for disconnections" )
@@ -570,11 +571,19 @@ func testDeliveryFromNodes(t *testing.T, nodes, chunkCount int, skipCheck bool)
570571 simulation .NewPeerEventsFilter ().Drop (),
571572 )
572573
574+ var disconnected atomic.Value
573575 go func () {
574576 for d := range disconnections {
575577 if d .Error != nil {
576578 log .Error ("peer drop" , "node" , d .NodeID , "peer" , d .PeerID )
577- t .Fatal (d .Error )
579+ disconnected .Store (true )
580+ }
581+ }
582+ }()
583+ defer func () {
584+ if err != nil {
585+ if yes , ok := disconnected .Load ().(bool ); ok && yes {
586+ err = errors .New ("disconnect events received" )
578587 }
579588 }
580589 }()
@@ -595,6 +604,9 @@ func testDeliveryFromNodes(t *testing.T, nodes, chunkCount int, skipCheck bool)
595604 if ! success {
596605 return fmt .Errorf ("Test failed, chunks not available on all nodes" )
597606 }
607+ if err := <- retErrC ; err != nil {
608+ t .Fatalf ("requesting chunks: %v" , err )
609+ }
598610 log .Debug ("Test terminated successfully" )
599611 return nil
600612 })
@@ -675,7 +687,7 @@ func benchmarkDeliveryFromNodes(b *testing.B, nodes, chunkCount int, skipCheck b
675687 }
676688
677689 ctx := context .Background ()
678- result := sim .Run (ctx , func (ctx context.Context , sim * simulation.Simulation ) error {
690+ result := sim .Run (ctx , func (ctx context.Context , sim * simulation.Simulation ) ( err error ) {
679691 nodeIDs := sim .UpNodeIDs ()
680692 node := nodeIDs [len (nodeIDs )- 1 ]
681693
@@ -702,11 +714,19 @@ func benchmarkDeliveryFromNodes(b *testing.B, nodes, chunkCount int, skipCheck b
702714 simulation .NewPeerEventsFilter ().Drop (),
703715 )
704716
717+ var disconnected atomic.Value
705718 go func () {
706719 for d := range disconnections {
707720 if d .Error != nil {
708721 log .Error ("peer drop" , "node" , d .NodeID , "peer" , d .PeerID )
709- b .Fatal (d .Error )
722+ disconnected .Store (true )
723+ }
724+ }
725+ }()
726+ defer func () {
727+ if err != nil {
728+ if yes , ok := disconnected .Load ().(bool ); ok && yes {
729+ err = errors .New ("disconnect events received" )
710730 }
711731 }
712732 }()
0 commit comments