mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/swarm/swarm-smoke: fix error handling
This commit is contained in:
parent
2555743a62
commit
ca37153f3a
1 changed files with 31 additions and 15 deletions
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
|
@ -58,7 +59,6 @@ func slidingWindow(c *cli.Context) error {
|
||||||
uploadedBytes := 0
|
uploadedBytes := 0
|
||||||
networkDepth := 0
|
networkDepth := 0
|
||||||
errored := false
|
errored := false
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
for {
|
for {
|
||||||
seed := int(time.Now().UnixNano() / 1e6)
|
seed := int(time.Now().UnixNano() / 1e6)
|
||||||
|
|
@ -84,23 +84,39 @@ outer:
|
||||||
hashes = append(hashes, uploadResult{hash: hash, digest: fhash})
|
hashes = append(hashes, uploadResult{hash: hash, digest: fhash})
|
||||||
time.Sleep(time.Duration(syncDelay) * time.Second)
|
time.Sleep(time.Duration(syncDelay) * time.Second)
|
||||||
uploadedBytes += filesize * 1000
|
uploadedBytes += filesize * 1000
|
||||||
|
var wg sync.WaitGroup
|
||||||
for i, v := range hashes {
|
for i, v := range hashes {
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
timeout := time.After(30 * time.Second)
|
||||||
randIndex := 1 + rand.Intn(len(endpoints)-1)
|
errored = false
|
||||||
ruid := uuid.New()[:8]
|
wg.Add(1)
|
||||||
start := time.Now()
|
go func(i int, v uploadResult) {
|
||||||
err := fetch(v.hash, endpoints[randIndex], v.digest, ruid)
|
defer wg.Done()
|
||||||
fetchTime := time.Since(start)
|
for {
|
||||||
if err != nil {
|
select {
|
||||||
errored = true
|
case <-timeout:
|
||||||
log.Error("error retrieving hash", "hash idx", i, "err", err)
|
errored = true
|
||||||
metrics.GetOrRegisterCounter("sliding-window.single.error", nil).Inc(1)
|
log.Error("error retrieving hash. timeout", "hash idx", i, "err", err)
|
||||||
networkDepth = i
|
metrics.GetOrRegisterCounter("sliding-window.single.error", nil).Inc(1)
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
|
randIndex := 1 + rand.Intn(len(endpoints)-1)
|
||||||
|
ruid := uuid.New()[:8]
|
||||||
|
start := time.Now()
|
||||||
|
err := fetch(v.hash, endpoints[randIndex], v.digest, ruid)
|
||||||
|
fetchTime := time.Since(start)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
metrics.GetOrRegisterMeter("sliding-window.single.fetch-time", nil).Mark(int64(fetchTime))
|
||||||
|
}
|
||||||
|
}(i, v)
|
||||||
|
wg.Wait()
|
||||||
|
if errored {
|
||||||
break outer
|
break outer
|
||||||
}
|
}
|
||||||
|
networkDepth = i
|
||||||
metrics.GetOrRegisterMeter("sliding-window.single.fetch-time", nil).Mark(int64(fetchTime))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue