Merge pull request #434 from ethersphere/smoke_test_refactor

cmd/swarm/swarm-smoke: extract cluster type and from/to ports and scheme
This commit is contained in:
Anton Evangelatov 2018-04-26 17:20:50 +02:00 committed by GitHub
commit 9d43e34a7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 15 deletions

View file

@ -17,7 +17,6 @@
package main package main
import ( import (
"fmt"
"os" "os"
"sort" "sort"
@ -28,17 +27,15 @@ import (
) )
var ( var (
endpoints []string endpoints []string
endpoint string includeLocalhost bool
filesize int cluster string
scheme string
filesize int
from int
to int
) )
func init() {
for port := 8501; port <= 8512; port++ {
endpoints = append(endpoints, fmt.Sprintf("http://%v.testing.swarm-gateways.net", port))
}
}
func main() { func main() {
log.PrintOrigins(true) log.PrintOrigins(true)
log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(true)))) log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(true))))
@ -49,10 +46,33 @@ func main() {
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "bzz-api", Name: "cluster-endpoint",
Value: endpoints[0], Value: "testing",
Usage: "upload node endpoint", Usage: "cluster to point to (open, or testing)",
Destination: &endpoint, Destination: &cluster,
},
cli.IntFlag{
Name: "cluster-from",
Value: 8501,
Usage: "swarm node (from)",
Destination: &from,
},
cli.IntFlag{
Name: "cluster-to",
Value: 8512,
Usage: "swarm node (to)",
Destination: &to,
},
cli.StringFlag{
Name: "cluster-scheme",
Value: "http",
Usage: "http or https",
Destination: &scheme,
},
cli.BoolFlag{
Name: "include-localhost",
Usage: "whether to include localhost:8500 as an endpoint",
Destination: &includeLocalhost,
}, },
cli.IntFlag{ cli.IntFlag{
Name: "filesize", Name: "filesize",

View file

@ -20,10 +20,22 @@ import (
cli "gopkg.in/urfave/cli.v1" cli "gopkg.in/urfave/cli.v1"
) )
func generateEndpoints(scheme string, cluster string, from int, to int) {
for port := from; port <= to; port++ {
endpoints = append(endpoints, fmt.Sprintf("%s://%v.%s.swarm-gateways.net", scheme, port, cluster))
}
if includeLocalhost {
endpoints = append(endpoints, "http://localhost:8500")
}
}
func cliUploadAndSync(c *cli.Context) error { func cliUploadAndSync(c *cli.Context) error {
defer func(now time.Time) { log.Info("total time", "time", time.Since(now), "size", filesize) }(time.Now()) defer func(now time.Time) { log.Info("total time", "time", time.Since(now), "size", filesize) }(time.Now())
log.Info("uploading and syncing") generateEndpoints(scheme, cluster, from, to)
log.Info("uploading to " + endpoints[0] + " and syncing")
f, cleanup := generateRandomFile(filesize * 1000000) f, cleanup := generateRandomFile(filesize * 1000000)
defer cleanup() defer cleanup()