swarm/network/stream: fixed iterations for snapshot tests

This commit is contained in:
Fabio Barone 2018-09-27 10:21:47 -05:00
parent a2a1131a8b
commit d1457c7b3c
2 changed files with 25 additions and 59 deletions

View file

@ -203,15 +203,13 @@ func runFileRetrievalTest(nodeCount int) error {
// File retrieval check is repeated until all uploaded files are retrieved from all nodes // File retrieval check is repeated until all uploaded files are retrieved from all nodes
// or until the timeout is reached. // or until the timeout is reached.
allSuccess := false REPEAT:
for !allSuccess { for {
allSuccess = true
for _, id := range nodeIDs { for _, id := range nodeIDs {
//for each expected chunk, check if it is in the local store //for each expected file, check if it is in the local store
localSuccess := true
item, ok := sim.NodeItem(id, bucketKeyFileStore) item, ok := sim.NodeItem(id, bucketKeyFileStore)
if !ok { if !ok {
return fmt.Errorf("No registry") return fmt.Errorf("No filestore")
} }
fileStore := item.(*storage.FileStore) fileStore := item.(*storage.FileStore)
//check all chunks //check all chunks
@ -219,23 +217,16 @@ func runFileRetrievalTest(nodeCount int) error {
reader, _ := fileStore.Retrieve(context.TODO(), hash) 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 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])) { 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) log.Warn("Retrieve error", "err", err, "hash", hash, "nodeId", id)
time.Sleep(500 * time.Millisecond)
continue REPEAT
} else { } else {
log.Debug(fmt.Sprintf("File with root hash %x successfully retrieved", hash)) 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 { 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 // File retrieval check is repeated until all uploaded files are retrieved from all nodes
// or until the timeout is reached. // or until the timeout is reached.
allSuccess := false REPEAT:
for !allSuccess { for {
allSuccess = true
for _, id := range nodeIDs { for _, id := range nodeIDs {
//for each expected chunk, check if it is in the local store //for each expected chunk, check if it is in the local store
localSuccess := true
//check on the node's FileStore (netstore) //check on the node's FileStore (netstore)
item, ok := sim.NodeItem(id, bucketKeyFileStore) item, ok := sim.NodeItem(id, bucketKeyFileStore)
if !ok { if !ok {
return fmt.Errorf("No registry") return fmt.Errorf("No filestore")
} }
fileStore := item.(*storage.FileStore) fileStore := item.(*storage.FileStore)
//check all chunks //check all chunks
for _, hash := range conf.hashes { for _, hash := range conf.hashes {
reader, _ := fileStore.Retrieve(context.TODO(), hash) 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) { if s, err := reader.Size(ctx, nil); err != nil || s != int64(chunkSize) {
localSuccess = false log.Warn("Retrieve error", "err", err, "hash", hash, "nodeId", id, "size", s)
log.Warn("Retrieve error", "err", err, "hash", hash, "nodeId", id) time.Sleep(500 * time.Millisecond)
continue REPEAT
} else { } 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 { if result.Error != nil {

View file

@ -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 // File retrieval check is repeated until all uploaded files are retrieved from all nodes
// or until the timeout is reached. // or until the timeout is reached.
allSuccess := false
var gDir string var gDir string
var globalStore *mockdb.GlobalStore var globalStore *mockdb.GlobalStore
if *useMockStore { if *useMockStore {
@ -285,12 +284,11 @@ func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulatio
} }
}() }()
} }
for !allSuccess { REPEAT:
allSuccess = true for {
for _, id := range nodeIDs { for _, id := range nodeIDs {
//for each expected chunk, check if it is in the local store //for each expected chunk, check if it is in the local store
localChunks := conf.idToChunksMap[id] localChunks := conf.idToChunksMap[id]
localSuccess := true
for _, ch := range localChunks { for _, ch := range localChunks {
//get the real chunk by the index in the index array //get the real chunk by the index in the index array
chunk := conf.hashes[ch] chunk := conf.hashes[ch]
@ -312,9 +310,9 @@ func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulatio
} }
if err != nil { if err != nil {
log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id)) log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id))
localSuccess = false
// Do not get crazy with logging the warn message // Do not get crazy with logging the warn message
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
continue REPEAT
} else { } else {
evt := &simulations.Event{ evt := &simulations.Event{
Type: EventTypeChunkArrived, 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)) 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 // File retrieval check is repeated until all uploaded files are retrieved from all nodes
// or until the timeout is reached. // or until the timeout is reached.
allSuccess := false REPEAT:
for !allSuccess { for {
allSuccess = true
for _, id := range nodeIDs { for _, id := range nodeIDs {
//for each expected chunk, check if it is in the local store //for each expected chunk, check if it is in the local store
localChunks := conf.idToChunksMap[id] localChunks := conf.idToChunksMap[id]
localSuccess := true
for _, ch := range localChunks { for _, ch := range localChunks {
//get the real chunk by the index in the index array //get the real chunk by the index in the index array
chunk := conf.hashes[ch] chunk := conf.hashes[ch]
@ -523,23 +512,16 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int)
} }
if err != nil { if err != nil {
log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id)) log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id))
localSuccess = false
// Do not get crazy with logging the warn message // Do not get crazy with logging the warn message
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
continue REPEAT
} else { } else {
log.Debug(fmt.Sprintf("Chunk %s IS FOUND for id %s", chunk, id)) 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 { if result.Error != nil {