aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/swarm/swarm-smoke/upload_speed.go
diff options
context:
space:
mode:
authorElad <theman@elad.im>2019-01-30 16:46:44 +0800
committerRafael Matias <rafael@skyle.net>2019-02-19 20:05:26 +0800
commit7038b5734c9068fb67851b9a21d771ae93aef1fd (patch)
treef4100ee51422a3ecca23e536833c8ba4bff51506 /cmd/swarm/swarm-smoke/upload_speed.go
parent1ecf2860cff6e4da75abbd1e6b30a9b1d69c5a12 (diff)
downloadgo-tangerine-7038b5734c9068fb67851b9a21d771ae93aef1fd.tar
go-tangerine-7038b5734c9068fb67851b9a21d771ae93aef1fd.tar.gz
go-tangerine-7038b5734c9068fb67851b9a21d771ae93aef1fd.tar.bz2
go-tangerine-7038b5734c9068fb67851b9a21d771ae93aef1fd.tar.lz
go-tangerine-7038b5734c9068fb67851b9a21d771ae93aef1fd.tar.xz
go-tangerine-7038b5734c9068fb67851b9a21d771ae93aef1fd.tar.zst
go-tangerine-7038b5734c9068fb67851b9a21d771ae93aef1fd.zip
cmd/swarm/swarm-smoke: sliding window test (#18967)
(cherry picked from commit b91bf08876ca4da0c2a843a9ed3e88d64427cfb8)
Diffstat (limited to 'cmd/swarm/swarm-smoke/upload_speed.go')
-rw-r--r--cmd/swarm/swarm-smoke/upload_speed.go55
1 files changed, 8 insertions, 47 deletions
diff --git a/cmd/swarm/swarm-smoke/upload_speed.go b/cmd/swarm/swarm-smoke/upload_speed.go
index 4a355baf8..943c93240 100644
--- a/cmd/swarm/swarm-smoke/upload_speed.go
+++ b/cmd/swarm/swarm-smoke/upload_speed.go
@@ -17,54 +17,18 @@
package main
import (
- "bytes"
+ "crypto/md5"
+ crand "crypto/rand"
"fmt"
- "os"
+ "io"
"time"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
- "github.com/ethereum/go-ethereum/swarm/testutil"
cli "gopkg.in/urfave/cli.v1"
)
-var endpoint string
-
-//just use the first endpoint
-func generateEndpoint(scheme string, cluster string, app string, from int) {
- if cluster == "prod" {
- endpoint = fmt.Sprintf("%s://%v.swarm-gateways.net", scheme, from)
- } else if cluster == "private-internal" {
- endpoint = fmt.Sprintf("%s://swarm-private-internal-%v:8500", scheme, from)
- } else {
- endpoint = fmt.Sprintf("%s://%s-%v-%s.stg.swarm-gateways.net", scheme, app, from, cluster)
- }
-}
-
-func cliUploadSpeed(c *cli.Context) error {
- log.PrintOrigins(true)
- log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(verbosity), log.StreamHandler(os.Stdout, log.TerminalFormat(true))))
-
- metrics.GetOrRegisterCounter("upload-speed", nil).Inc(1)
-
- errc := make(chan error)
- go func() {
- errc <- uploadSpeed(c)
- }()
-
- select {
- case err := <-errc:
- if err != nil {
- metrics.GetOrRegisterCounter("upload-speed.fail", nil).Inc(1)
- }
- return err
- case <-time.After(time.Duration(timeout) * time.Second):
- metrics.GetOrRegisterCounter("upload-speed.timeout", nil).Inc(1)
- return fmt.Errorf("timeout after %v sec", timeout)
- }
-}
-
func uploadSpeed(c *cli.Context) error {
defer func(now time.Time) {
totalTime := time.Since(now)
@@ -73,25 +37,22 @@ func uploadSpeed(c *cli.Context) error {
metrics.GetOrRegisterCounter("upload-speed.total-time", nil).Inc(int64(totalTime))
}(time.Now())
- generateEndpoint(scheme, cluster, appName, from)
+ endpoint := generateEndpoint(scheme, cluster, appName, from)
seed := int(time.Now().UnixNano() / 1e6)
log.Info("uploading to "+endpoint, "seed", seed)
- randomBytes := testutil.RandomBytes(seed, filesize*1000)
+ h := md5.New()
+ r := io.TeeReader(io.LimitReader(crand.Reader, int64(filesize*1000)), h)
t1 := time.Now()
- hash, err := upload(&randomBytes, endpoint)
+ hash, err := upload(r, filesize*1000, endpoint)
if err != nil {
log.Error(err.Error())
return err
}
metrics.GetOrRegisterCounter("upload-speed.upload-time", nil).Inc(int64(time.Since(t1)))
- fhash, err := digest(bytes.NewReader(randomBytes))
- if err != nil {
- log.Error(err.Error())
- return err
- }
+ fhash := h.Sum(nil)
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fhash))
return nil