sweet/benchmarks/cockroachdb: fix ping retry This benchmark waits for the server to come up by running a "ping" command in a loop. However, it only calls "CombinedOutput" in the loop, and according to the exec.Cmd documentation, you're only supposed to call it once. Fix this by reconstructing the Cmd on every iteration. While we're here, we also put a timeout on the ping command in case it freezes. I've had this happen a few times during experiments. Change-Id: Ic846da2b4bcece2fbb2af68843362398ac609c05 Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/619718 Auto-Submit: Austin Clements <austin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
diff --git a/sweet/benchmarks/cockroachdb/main.go b/sweet/benchmarks/cockroachdb/main.go index 4393450..afbf413 100644 --- a/sweet/benchmarks/cockroachdb/main.go +++ b/sweet/benchmarks/cockroachdb/main.go
@@ -423,12 +423,15 @@ pingArgs := cfg.bench.args pingArgs = append(pingArgs, cfg.bench.pingArgs...) pingArgs = append(pingArgs, pgurls...) - pingCmd := exec.Command(cfg.cockroachdbBin, pingArgs...) - pingStart := time.Now() var pingOutput []byte var pingErr error - for time.Now().Sub(pingStart) < 30*time.Second { - if pingOutput, pingErr = pingCmd.CombinedOutput(); pingErr == nil { + pingStart := time.Now() + for time.Since(pingStart) < 30*time.Second { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + pingCmd := exec.CommandContext(ctx, cfg.cockroachdbBin, pingArgs...) + pingOutput, pingErr = pingCmd.CombinedOutput() + cancel() + if pingErr == nil { break } }