cmd/swarm/swarm-smoke: dont fail hard on timeout for sliding window

This commit is contained in:
Elad Nachmias 2019-01-28 20:19:23 +07:00
parent 2bc8addb42
commit e3a5773600
3 changed files with 23 additions and 7 deletions

View file

@ -147,25 +147,25 @@ func main() {
Name: "upload_and_sync",
Aliases: []string{"c"},
Usage: "upload and sync",
Action: wrapCliCommand("upload-and-sync", uploadAndSync),
Action: wrapCliCommand("upload-and-sync", true, uploadAndSync),
},
{
Name: "feed_sync",
Aliases: []string{"f"},
Usage: "feed update generate, upload and sync",
Action: wrapCliCommand("feed-and-sync", feedUploadAndSync),
Action: wrapCliCommand("feed-and-sync", true, feedUploadAndSync),
},
{
Name: "upload_speed",
Aliases: []string{"u"},
Usage: "measure upload speed",
Action: wrapCliCommand("upload-speed", uploadSpeed),
Action: wrapCliCommand("upload-speed", true, uploadSpeed),
},
{
Name: "sliding_window",
Aliases: []string{"s"},
Usage: "measure network aggregate capacity",
Action: wrapCliCommand("sliding-window", slidingWindow),
Action: wrapCliCommand("sliding-window", false, slidingWindow),
},
}

View file

@ -111,12 +111,12 @@ outer:
break outer
}
networkDepth = i
metrics.GetOrRegisterGauge("sliding-window.network-depth", nil).Update(int64(networkDepth))
}
}
log.Info("sliding window test finished", "errored?", errored, "networkDepth", networkDepth, "networkDepth(kb)", networkDepth*filesize)
log.Info("stats", "uploadedFiles", len(hashes), "uploadedKb", uploadedBytes/1000, "filesizeKb", filesize)
metrics.GetOrRegisterMeter("sliding-window.network-depth", nil).Mark(int64(networkDepth))
return nil
}

View file

@ -43,15 +43,31 @@ var (
commandName = ""
)
func wrapCliCommand(name string, command func(*cli.Context) error) func(*cli.Context) error {
func wrapCliCommand(name string, killOnTimeout bool, command func(*cli.Context) error) func(*cli.Context) error {
return func(ctx *cli.Context) error {
log.PrintOrigins(true)
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(verbosity), log.StreamHandler(os.Stdout, log.TerminalFormat(true))))
defer func(now time.Time) {
totalTime := time.Since(now)
log.Info("total time", "time", totalTime)
metrics.GetOrRegisterCounter(name+".total-time", nil).Inc(int64(totalTime))
}(time.Now())
log.Info("smoke test starting", "task", name, "timeout", timeout)
commandName = name
metrics.GetOrRegisterCounter(name, nil).Inc(1)
errc := make(chan error)
done := make(chan struct{})
if killOnTimeout {
go func() {
<-time.After(time.Duration(timeout) * time.Second)
close(done)
}()
}
go func() {
errc <- command(ctx)
}()
@ -62,7 +78,7 @@ func wrapCliCommand(name string, command func(*cli.Context) error) func(*cli.Con
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.fail", name), nil).Inc(1)
}
return err
case <-time.After(time.Duration(timeout) * time.Second):
case <-done:
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.timeout", name), nil).Inc(1)
return fmt.Errorf("timeout after %v sec", timeout)
}