swarm: removed parallelism in swap tests

This commit is contained in:
Fabio Barone 2018-12-17 19:55:16 -05:00
parent f46fdefcef
commit 63713a458e

View file

@ -119,7 +119,6 @@ func TestSwapNetworkSymmetricFileUpload(t *testing.T) {
for _, id := range nodeIDs { for _, id := range nodeIDs {
item, ok := sim.NodeItem(id, bucketKeySwarm) item, ok := sim.NodeItem(id, bucketKeySwarm)
if !ok { if !ok {
log.Error("No swarm")
return errors.New("No swarm") return errors.New("No swarm")
} }
swarm := item.(*Swarm) swarm := item.(*Swarm)
@ -344,9 +343,7 @@ func TestSwapNetworkAsymmetricFileUpload(t *testing.T) {
} }
balancesMap[node] = subBalances balancesMap[node] = subBalances
} }
return nil return nil
}) })
if result.Error != nil { if result.Error != nil {
@ -384,7 +381,7 @@ func TestSwapNetworkAsymmetricFileUpload(t *testing.T) {
log.Debug("test terminated") log.Debug("test terminated")
} }
// uploadFile, uploads a short file to the swarm instance // uploadRandomFileSize, uploads a file of random size to the swarm instance
// using the api.Put method. // using the api.Put method.
func uploadRandomFileSize(swarm *Swarm, size int) (storage.Address, string, error) { func uploadRandomFileSize(swarm *Swarm, size int) (storage.Address, string, error) {
b := make([]byte, size) b := make([]byte, size)
@ -415,8 +412,6 @@ func retrieveForSwap(
files[i], files[j] = files[j], files[i] files[i], files[j] = files[j], files[i]
}) })
lock := &sync.Mutex{}
nodeIDs := sim.UpNodeIDs() nodeIDs := sim.UpNodeIDs()
totalFoundCount := uint64(0) totalFoundCount := uint64(0)
@ -424,13 +419,8 @@ func retrieveForSwap(
for _, id := range nodeIDs { for _, id := range nodeIDs {
waitGrp := sync.WaitGroup{}
swarm := sim.Service("swarm", id).(*Swarm) swarm := sim.Service("swarm", id).(*Swarm)
for _, f := range files { for _, f := range files {
f := f
waitGrp.Add(1)
go func() {
defer waitGrp.Done()
log.Debug("api get: check file", "node", id.String(), "key", f.addr.String(), "total files found", totalFoundCount) log.Debug("api get: check file", "node", id.String(), "key", f.addr.String(), "total files found", totalFoundCount)
r, _, _, _, err := swarm.api.Get(context.TODO(), api.NOOPDecrypt, f.addr, "/") r, _, _, _, err := swarm.api.Get(context.TODO(), api.NOOPDecrypt, f.addr, "/")
@ -450,17 +440,13 @@ func retrieveForSwap(
} }
log.Info("api get: file found", "node", id.String(), "key", f.addr.String(), "content", data, "files found", totalFoundCount) log.Info("api get: file found", "node", id.String(), "key", f.addr.String(), "content", data, "files found", totalFoundCount)
lock.Lock()
defer lock.Unlock()
totalFoundCount++ totalFoundCount++
log.Debug("status", "totalCheckCount", totalCheckCount, "totalFoundCount", totalFoundCount) log.Debug("status", "totalCheckCount", totalCheckCount, "totalFoundCount", totalFoundCount)
}()
} }
waitGrp.Wait()
} }
log.Info("check stats", "total check count", totalCheckCount, "total files found", totalFoundCount) log.Info("check stats", "total check count", totalCheckCount, "total files found", totalFoundCount, "missing", missing)
return totalCheckCount - totalFoundCount return totalCheckCount - totalFoundCount
} }