Skip to content

Commit 39f0f5c

Browse files
bradfitzadonovan
authored andcommitted
cmd/stress: add -failfast flag
Change-Id: If73c915bd27f0e93bde77a1f1ab634d78850f19b Reviewed-on: https://go-review.googlesource.com/c/tools/+/751720 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
1 parent 063c264 commit 39f0f5c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

cmd/stress/stress.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ import (
3131
)
3232

3333
var (
34-
flagCount = flag.Int("count", 0, "stop after `N` runs (default never stop)")
35-
flagFailure = flag.String("failure", "", "fail only if output matches `regexp`")
36-
flagIgnore = flag.String("ignore", "", "ignore failure if output matches `regexp`")
37-
flagKill = flag.Bool("kill", true, "kill timed out processes if true, otherwise just print pid (to attach with gdb)")
38-
flagOutput = flag.String("o", defaultPrefix(), "output failure logs to `path` plus a unique suffix")
39-
flagP = flag.Int("p", runtime.NumCPU(), "run `N` processes in parallel")
40-
flagTimeout = flag.Duration("timeout", 10*time.Minute, "timeout each process after `duration`")
34+
flagCount = flag.Int("count", 0, "stop after `N` runs (default never stop)")
35+
flagFailfast = flag.Bool("failfast", false, "exit on first failure and write failure output to stderr")
36+
flagFailure = flag.String("failure", "", "fail only if output matches `regexp`")
37+
flagIgnore = flag.String("ignore", "", "ignore failure if output matches `regexp`")
38+
flagKill = flag.Bool("kill", true, "kill timed out processes if true, otherwise just print pid (to attach with gdb)")
39+
flagOutput = flag.String("o", defaultPrefix(), "output failure logs to `path` plus a unique suffix")
40+
flagP = flag.Int("p", runtime.NumCPU(), "run `N` processes in parallel")
41+
flagTimeout = flag.Duration("timeout", 10*time.Minute, "timeout each process after `duration`")
4142
)
4243

4344
func init() {
@@ -158,6 +159,10 @@ func main() {
158159
runs++
159160
if len(out) > 0 {
160161
fails++
162+
if *flagFailfast {
163+
os.Stderr.Write(out)
164+
os.Exit(1)
165+
}
161166
dir, path := filepath.Split(*flagOutput)
162167
f, err := os.CreateTemp(dir, path)
163168
if err != nil {

0 commit comments

Comments
 (0)