Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roachtest: don't reuse clusters after test failure #38746

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/cmd/roachtest/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,8 @@ func (c *cluster) doDestroy(ctx context.Context, l *logger) <-chan struct{} {
l.PrintfCtx(ctx, "destroying cluster %s...", c)
c.status("destroying cluster")
// We use a non-cancelable context for running this command. Once we got
// here, the cluster cannot be destroyed again, so we really want this command to succeed.
// here, the cluster cannot be destroyed again, so we really want this
// command to succeed.
if err := execCmd(context.Background(), l, roachprod, "destroy", c.name); err != nil {
l.ErrorfCtx(ctx, "error destroying cluster %s: %s", c, err)
} else {
Expand Down
32 changes: 21 additions & 11 deletions pkg/cmd/roachtest/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,29 +466,37 @@ func (r *testRunner) runWorker(
}
l.PrintfCtx(ctx, msg)
}
// If a test failed and debug was set, we bail.
if (err != nil || t.Failed()) && debug {
if err != nil || t.Failed() {
failureMsg := fmt.Sprintf("%s (%d) - ", testToRun.spec.Name, testToRun.runNum)
if err != nil {
failureMsg += err.Error()
} else {
failureMsg += t.FailureMsg()
}
// Save the cluster for future debugging.
c.Save(ctx, failureMsg, l)

if debug {
// Save the cluster for future debugging.
c.Save(ctx, failureMsg, l)

// Continue with a fresh cluster.
c = nil
} else {
// On any test failure or error, we destroy the cluster. We could be
// more selective, but this sounds safer.
l.PrintfCtx(ctx, "destroying cluster %s because: %s", c, failureMsg)
c.Destroy(ctx, closeLogger, l)
c = nil
}

if err != nil {
return err
}

// Continue with a fresh cluster.
c = nil
}
}
}

// An error is returned in exceptional situations. The cluster cannot be reused
// if an error is returned.
// An error is returned if the test is still running (on another goroutine) when
// this returns. This happens when the test doesn't respond to cancellation.
// Returns true if the test is considered to have passed, false otherwise.
//
// Args:
Expand Down Expand Up @@ -629,8 +637,8 @@ func (r *testRunner) runTest(
l.PrintfCtx(ctx, "cluster needs to survive until %s, but has expiration: %s. Extending.",
minExp, c.expiration)
if err := c.Extend(ctx, extend, l); err != nil {
t.printfAndFail(0 /* skip */, "failed to extend cluster")
return false, err
t.printfAndFail(0 /* skip */, "failed to extend cluster: %s", err)
return false, nil
}
}

Expand Down Expand Up @@ -692,6 +700,8 @@ func (r *testRunner) runTest(
msg := "test timed out and afterwards failed to respond to cancelation"
t.l.PrintfCtx(ctx, msg)
collectClusterLogsOnce.Do(func() { r.collectClusterLogs(ctx, c, t.l) })
// We return an error here because the test goroutine is still running, so
// we want to alert the caller of this unusual situation.
return false, fmt.Errorf(msg)
}
}
Expand Down