Skip to content

Commit

Permalink
Retry starting registry server in tests
Browse files Browse the repository at this point in the history
For the case when previous test did not yet close teh socket

Signed-off-by: Yulia Gaponenko <[email protected]>
  • Loading branch information
mariash authored and barthy1 committed Oct 5, 2015
1 parent a7f5d5a commit 9b1840f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions registry/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (s *server) start(username string, password string, host string, port int,
}

func (s *server) Stop() error {
if s.listener == nil {
return bosherr.Error("Stopping not-started registry server")
}

s.logger.Debug(s.logTag, "Stopping registry server")
err := s.listener.Close()
if err != nil {
Expand Down
25 changes: 22 additions & 3 deletions registry/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"net/http"
"strings"
"time"

boshlog "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/logger"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/ginkgo"
Expand All @@ -21,15 +22,33 @@ var _ = Describe("Server", func() {
client helperClient
)

retryStartingServer := func() (Server, error) {
var err error
var server Server
logger := boshlog.NewLogger(boshlog.LevelNone)
serverFactory := NewServerManager(logger)

attempts := 0
for attempts < 3 {
server, err = serverFactory.Start("fake-user", "fake-password", "localhost", 6901)
if err == nil {
return server, nil
}

attempts++
time.Sleep(1 * time.Second)
}

return nil, err
}

BeforeEach(func() {
registryHost := "localhost:6901"
registryURL = fmt.Sprintf("http://fake-user:fake-password@%s", registryHost)
incorrectAuthRegistryURL = fmt.Sprintf("http://incorrect-user:incorrect-password@%s", registryHost)
logger := boshlog.NewLogger(boshlog.LevelNone)

serverFactory := NewServerManager(logger)
var err error
server, err = serverFactory.Start("fake-user", "fake-password", "localhost", 6901)
server, err = retryStartingServer() // wait for previous test to close socket if still open
Expect(err).ToNot(HaveOccurred())

transport := &http.Transport{DisableKeepAlives: true}
Expand Down

0 comments on commit 9b1840f

Please sign in to comment.