Skip to content

Commit ad80844

Browse files
authored
Merge pull request #111 from ZhouXing19/fix-Start
Make `Start()` to a no-op if testserver is started
2 parents 8efcbcb + aaf2f33 commit ad80844

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

testserver/testserver.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,22 @@ func (ts *testServerImpl) pollListeningURLFile() error {
459459
// Start runs the process, returning an error on any problems,
460460
// including being unable to start, but not unexpected failure.
461461
// It should only be called once in the lifetime of a TestServer object.
462+
// If the server is already running, this function is a no-op.
463+
// If the server stopped or failed, please don't use ts.Start()
464+
// to restart a testserver, but use NewTestServer().
462465
func (ts *testServerImpl) Start() error {
463466
ts.mu.Lock()
464467
if ts.state != stateNew {
465468
ts.mu.Unlock()
466-
return errors.New("Start() can only be called once")
469+
switch ts.state {
470+
case stateRunning:
471+
return nil // No-op if server is already running.
472+
case stateStopped, stateFailed:
473+
// Start() can only be called once.
474+
return errors.New(
475+
"Start() cannot be used to restart a stopped or failed server. " +
476+
"Please use NewTestServer()")
477+
}
467478
}
468479
ts.state = stateRunning
469480
ts.mu.Unlock()

0 commit comments

Comments
 (0)