add sync-delay and single configurations to swarm smoke tests

This commit is contained in:
Anton Evangelatov 2018-12-06 17:01:39 +01:00
parent c38d2508de
commit 73fc234634
2 changed files with 34 additions and 3 deletions

View file

@ -45,10 +45,12 @@ var (
appName string appName string
scheme string scheme string
filesize int filesize int
syncDelay int
from int from int
to int to int
verbosity int verbosity int
timeout int timeout int
single bool
) )
func main() { func main() {
@ -99,6 +101,12 @@ func main() {
Usage: "file size for generated random file in KB", Usage: "file size for generated random file in KB",
Destination: &filesize, Destination: &filesize,
}, },
cli.IntFlag{
Name: "sync-delay",
Value: 5,
Usage: "duration of delay in seconds to wait for content to be synced",
Destination: &syncDelay,
},
cli.IntFlag{ cli.IntFlag{
Name: "verbosity", Name: "verbosity",
Value: 1, Value: 1,
@ -111,6 +119,11 @@ func main() {
Usage: "timeout in seconds after which kill the process", Usage: "timeout in seconds after which kill the process",
Destination: &timeout, Destination: &timeout,
}, },
cli.BoolFlag{
Name: "single",
Usage: "whether to fetch content from a single node or from all nodes",
Destination: &single,
},
} }
app.Flags = append(app.Flags, []cli.Flag{ app.Flags = append(app.Flags, []cli.Flag{

View file

@ -25,6 +25,7 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"math/rand"
"net/http" "net/http"
"net/http/httptrace" "net/http/httptrace"
"os" "os"
@ -112,10 +113,11 @@ func uploadAndSync(c *cli.Context) error {
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fhash)) log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fhash))
time.Sleep(3 * time.Second) time.Sleep(time.Duration(syncDelay) * time.Second)
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
for _, endpoint := range endpoints { if single {
randIndex := 1 + rand.Intn(len(endpoints)-1)
ruid := uuid.New()[:8] ruid := uuid.New()[:8]
wg.Add(1) wg.Add(1)
go func(endpoint string, ruid string) { go func(endpoint string, ruid string) {
@ -128,7 +130,23 @@ func uploadAndSync(c *cli.Context) error {
wg.Done() wg.Done()
return return
} }
}(endpoint, ruid) }(endpoints[randIndex], ruid)
} else {
for _, endpoint := range endpoints {
ruid := uuid.New()[:8]
wg.Add(1)
go func(endpoint string, ruid string) {
for {
err := fetch(hash, endpoint, fhash, ruid)
if err != nil {
continue
}
wg.Done()
return
}
}(endpoint, ruid)
}
} }
wg.Wait() wg.Wait()
log.Info("all endpoints synced random file successfully") log.Info("all endpoints synced random file successfully")