swarm/network/stream: removed REPEAT retry loop

This commit is contained in:
Fabio Barone 2019-05-10 08:30:51 -05:00
parent f8518d26c6
commit 25831b3bf2

View file

@ -274,44 +274,37 @@ func runPureRetrievalTest(nodeCount int, chunkCount int) error {
log.Debug("starting retrieval") log.Debug("starting retrieval")
cnt := 0 cnt := 0
REPEAT: for _, id := range nodeIDs {
for { item, ok := sim.NodeItem(id, bucketKeyFileStore)
for _, id := range nodeIDs { if !ok {
item, ok := sim.NodeItem(id, bucketKeyFileStore) return fmt.Errorf("No filestore")
if !ok { }
return fmt.Errorf("No filestore") fileStore := item.(*storage.FileStore)
} for _, chunk := range chunks {
fileStore := item.(*storage.FileStore) reader, _ := fileStore.Retrieve(context.TODO(), chunk.Address())
for _, chunk := range chunks { content := make([]byte, chunkSize)
reader, _ := fileStore.Retrieve(context.TODO(), chunk.Address()) size, err := reader.Read(content)
content := make([]byte, chunkSize) //check chunk size and content
size, err := reader.Read(content) ok := true
//check chunk size and content if err != io.EOF {
ok := true log.Debug("Retrieve error", "err", err, "hash", chunk.Address(), "nodeId", id)
if err != io.EOF { ok = false
log.Debug("Retrieve error", "err", err, "hash", chunk.Address(), "nodeId", id) }
ok = false if size != chunkSize {
} log.Debug("size not equal chunkSize", "size", size, "hash", chunk.Address(), "nodeId", id)
if size != chunkSize { ok = false
log.Debug("size not equal chunkSize", "size", size, "hash", chunk.Address(), "nodeId", id) }
ok = false // skip chunk "metadata" for chunk.Data()
} if !bytes.Equal(content, chunk.Data()[8:]) {
// skip chunk "metadata" for chunk.Data() log.Debug("content not equal chunk data", "hash", chunk.Address(), "nodeId", id)
if !bytes.Equal(content, chunk.Data()[8:]) { ok = false
log.Debug("content not equal chunk data", "hash", chunk.Address(), "nodeId", id) }
ok = false if !ok {
} return fmt.Errorf("Expected test to succeed at first run, but failed with chunk not found")
if !ok { }
time.Sleep(500 * time.Millisecond) log.Debug(fmt.Sprintf("chunk with root hash %x successfully retrieved", chunk.Address()))
// we continue trying if it failed cnt++
continue REPEAT
}
log.Debug(fmt.Sprintf("chunk with root hash %x successfully retrieved", chunk.Address()))
cnt++
}
} }
// we iterate sequentially, one after the other, so at this point we got all chunks
break
} }
log.Info("retrieval terminated, chunks retrieved: ", "count", cnt) log.Info("retrieval terminated, chunks retrieved: ", "count", cnt)
return nil return nil