Commit cc5412e0 authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

streamtest record err flaky test fix (#514)

* wait for all goroutines before returning all streamtest records
* remove unused mockValidator
parent 8b7bab1a
......@@ -21,10 +21,6 @@ import (
var chunkData = []byte("mockdata")
type mockValidator struct{}
func (_ mockValidator) Validate(_ swarm.Chunk) bool { return true }
// TestNetstoreRetrieval verifies that a chunk is asked from the network whenever
// it is not found locally
func TestNetstoreRetrieval(t *testing.T) {
......
......@@ -92,8 +92,10 @@ func (r *Recorder) NewStream(ctx context.Context, addr swarm.Address, h p2p.Head
if headler != nil {
streamOut.headers = headler(h)
}
record := &Record{in: recordIn, out: recordOut}
record := &Record{in: recordIn, out: recordOut, done: make(chan struct{})}
go func() {
defer close(record.done)
err := handler(ctx, p2p.Peer{Address: addr}, streamIn)
if err != nil && err != io.EOF {
record.setErr(err)
......@@ -119,6 +121,10 @@ func (r *Recorder) Records(addr swarm.Address, protocolName, protocolVersio, str
if !ok {
return nil, ErrRecordsNotFound
}
// wait for all records goroutines to terminate
for _, r := range records {
<-r.done
}
return records, nil
}
......@@ -153,6 +159,7 @@ type Record struct {
out *record
err error
errMu sync.Mutex
done chan struct{}
}
func (r *Record) In() []byte {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment