diff --git a/cmd/swarm/swarm-smoke/main.go b/cmd/swarm/swarm-smoke/main.go index 788021e47e..15a6911efc 100644 --- a/cmd/swarm/swarm-smoke/main.go +++ b/cmd/swarm/swarm-smoke/main.go @@ -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), }, } diff --git a/cmd/swarm/swarm-smoke/sliding_window.go b/cmd/swarm/swarm-smoke/sliding_window.go index 182dd071dc..3dd404c508 100644 --- a/cmd/swarm/swarm-smoke/sliding_window.go +++ b/cmd/swarm/swarm-smoke/sliding_window.go @@ -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 } diff --git a/cmd/swarm/swarm-smoke/util.go b/cmd/swarm/swarm-smoke/util.go index 6cd0d29401..2a3083bf57 100644 --- a/cmd/swarm/swarm-smoke/util.go +++ b/cmd/swarm/swarm-smoke/util.go @@ -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) }