diff --git a/swarm/network/stream/snapshot_retrieval_test.go b/swarm/network/stream/snapshot_retrieval_test.go index 82190b791b..56b11bcd05 100644 --- a/swarm/network/stream/snapshot_retrieval_test.go +++ b/swarm/network/stream/snapshot_retrieval_test.go @@ -203,15 +203,13 @@ func runFileRetrievalTest(nodeCount int) error { // File retrieval check is repeated until all uploaded files are retrieved from all nodes // or until the timeout is reached. - allSuccess := false - for !allSuccess { - allSuccess = true + REPEAT: + for { for _, id := range nodeIDs { - //for each expected chunk, check if it is in the local store - localSuccess := true + //for each expected file, check if it is in the local store item, ok := sim.NodeItem(id, bucketKeyFileStore) if !ok { - return fmt.Errorf("No registry") + return fmt.Errorf("No filestore") } fileStore := item.(*storage.FileStore) //check all chunks @@ -219,23 +217,16 @@ func runFileRetrievalTest(nodeCount int) error { reader, _ := fileStore.Retrieve(context.TODO(), hash) //check that we can read the file size and that it corresponds to the generated file size if s, err := reader.Size(ctx, nil); err != nil || s != int64(len(randomFiles[i])) { - //allSuccess = false - localSuccess = false log.Warn("Retrieve error", "err", err, "hash", hash, "nodeId", id) + time.Sleep(500 * time.Millisecond) + continue REPEAT } else { log.Debug(fmt.Sprintf("File with root hash %x successfully retrieved", hash)) } } - if !localSuccess { - allSuccess = false - break - } } + return nil } - if !allSuccess { - return fmt.Errorf("Not all retrievals succeeded!") - } - return nil }) if result.Error != nil { @@ -303,39 +294,32 @@ func runRetrievalTest(chunkCount int, nodeCount int) error { // File retrieval check is repeated until all uploaded files are retrieved from all nodes // or until the timeout is reached. - allSuccess := false - for !allSuccess { - allSuccess = true + REPEAT: + for { for _, id := range nodeIDs { //for each expected chunk, check if it is in the local store - localSuccess := true //check on the node's FileStore (netstore) item, ok := sim.NodeItem(id, bucketKeyFileStore) if !ok { - return fmt.Errorf("No registry") + return fmt.Errorf("No filestore") } fileStore := item.(*storage.FileStore) //check all chunks for _, hash := range conf.hashes { reader, _ := fileStore.Retrieve(context.TODO(), hash) - //check that we can read the file size and that it corresponds to the generated file size + //check that we can read the chunk size and that it corresponds to the generated chunk size if s, err := reader.Size(ctx, nil); err != nil || s != int64(chunkSize) { - localSuccess = false - log.Warn("Retrieve error", "err", err, "hash", hash, "nodeId", id) + log.Warn("Retrieve error", "err", err, "hash", hash, "nodeId", id, "size", s) + time.Sleep(500 * time.Millisecond) + continue REPEAT } else { - log.Debug(fmt.Sprintf("File with root hash %x successfully retrieved", hash)) + log.Debug(fmt.Sprintf("Chunk with root hash %x successfully retrieved", hash)) } } - if !localSuccess { - allSuccess = false - break - } } + // all nodes and files found, exit loop and return without error + return nil } - if !allSuccess { - return fmt.Errorf("Not all retrievals succeeded!") - } - return nil }) if result.Error != nil { diff --git a/swarm/network/stream/snapshot_sync_test.go b/swarm/network/stream/snapshot_sync_test.go index 1ec58c4d96..594f971b4c 100644 --- a/swarm/network/stream/snapshot_sync_test.go +++ b/swarm/network/stream/snapshot_sync_test.go @@ -269,7 +269,6 @@ func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulatio // File retrieval check is repeated until all uploaded files are retrieved from all nodes // or until the timeout is reached. - allSuccess := false var gDir string var globalStore *mockdb.GlobalStore if *useMockStore { @@ -285,12 +284,11 @@ func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulatio } }() } - for !allSuccess { - allSuccess = true + REPEAT: + for { for _, id := range nodeIDs { //for each expected chunk, check if it is in the local store localChunks := conf.idToChunksMap[id] - localSuccess := true for _, ch := range localChunks { //get the real chunk by the index in the index array chunk := conf.hashes[ch] @@ -312,9 +310,9 @@ func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulatio } if err != nil { log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id)) - localSuccess = false // Do not get crazy with logging the warn message time.Sleep(500 * time.Millisecond) + continue REPEAT } else { evt := &simulations.Event{ Type: EventTypeChunkArrived, @@ -325,16 +323,9 @@ func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulatio log.Debug(fmt.Sprintf("Chunk %s IS FOUND for id %s", chunk, id)) } } - if !localSuccess { - allSuccess = false - break - } } + return nil } - if !allSuccess { - return fmt.Errorf("Not all chunks succeeded!") - } - return nil }) } @@ -495,13 +486,11 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int) } // File retrieval check is repeated until all uploaded files are retrieved from all nodes // or until the timeout is reached. - allSuccess := false - for !allSuccess { - allSuccess = true + REPEAT: + for { for _, id := range nodeIDs { //for each expected chunk, check if it is in the local store localChunks := conf.idToChunksMap[id] - localSuccess := true for _, ch := range localChunks { //get the real chunk by the index in the index array chunk := conf.hashes[ch] @@ -523,23 +512,16 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int) } if err != nil { log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id)) - localSuccess = false // Do not get crazy with logging the warn message time.Sleep(500 * time.Millisecond) + continue REPEAT } else { log.Debug(fmt.Sprintf("Chunk %s IS FOUND for id %s", chunk, id)) } } - if !localSuccess { - allSuccess = false - break - } } + return nil } - if !allSuccess { - return fmt.Errorf("Not all chunks succeeded!") - } - return nil }) if result.Error != nil {