@@ -56,10 +56,9 @@ import (
5656 "testing"
5757 "time"
5858
59+ "github.com/cockroachdb/cockroach-go/v2/testserver/version"
5960 // Import postgres driver.
6061 _ "github.com/lib/pq"
61-
62- "github.com/cockroachdb/cockroach-go/v2/testserver/version"
6362)
6463
6564var customBinaryFlag = flag .String ("cockroach-binary" , "" , "Use specified cockroach binary" )
@@ -423,11 +422,22 @@ func (ts *testServerImpl) pollListeningURLFile() error {
423422// Start runs the process, returning an error on any problems,
424423// including being unable to start, but not unexpected failure.
425424// It should only be called once in the lifetime of a TestServer object.
425+ // If the server is already running, this function is a no-op.
426+ // If the server stopped or failed, please don't use ts.Start()
427+ // to restart a testserver, but use NewTestServer().
426428func (ts * testServerImpl ) Start () error {
427429 ts .mu .Lock ()
428430 if ts .state != stateNew {
429431 ts .mu .Unlock ()
430- return errors .New ("Start() can only be called once" )
432+ switch ts .state {
433+ case stateRunning :
434+ return nil // No-op if server is already running.
435+ case stateStopped , stateFailed :
436+ // Start() can only be called once.
437+ return errors .New (
438+ "Start() cannot be used to restart a stopped or failed server. " +
439+ "Please use NewTestServer()" )
440+ }
431441 }
432442 ts .state = stateRunning
433443 ts .mu .Unlock ()
0 commit comments