Skip to content

Commit

Permalink
HTTP Transporter fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson committed Jul 9, 2013
1 parent 4ee2054 commit 5e71312
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
Trace = 2
)

var LogLevel int = Trace //0
var LogLevel int = 0
var logger *log.Logger

func init() {
Expand Down
14 changes: 6 additions & 8 deletions http_transporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net"
"net/http"
"sync"
"time"
"testing"
"time"
)

//------------------------------------------------------------------------------
Expand All @@ -30,7 +30,6 @@ func TestHTTPTransporter(t *testing.T) {
server.Stop()
time.Sleep(testElectionTimeout * 2)

debugln("STATES: ", servers[1].State(), servers[2].State())
if servers[1].State() != Leader && servers[2].State() != Leader {
t.Fatal("Expected re-election:", servers[1].State(), servers[2].State())
}
Expand All @@ -43,7 +42,6 @@ func TestHTTPTransporter(t *testing.T) {
runTestHttpServers(t, &servers, transporter, f0, f1, f2)
}


//------------------------------------------------------------------------------
//
// Helper Functions
Expand All @@ -57,7 +55,7 @@ func runTestHttpServers(t *testing.T, servers *[]*Server, transporter *HTTPTrans
listeners := []net.Listener{}
for i, _ := range callbacks {
wg.Add(1)
port := 9000+i
port := 9000 + i

// Create raft server.
server := newTestServer(fmt.Sprintf("localhost:%d", port), transporter)
Expand All @@ -81,16 +79,16 @@ func runTestHttpServers(t *testing.T, servers *[]*Server, transporter *HTTPTrans
listeners = append(listeners, listener)

// Create wrapping HTTP server.
mux := http.NewServeMux()
mux := http.NewServeMux()
transporter.Install(server, mux)
httpServer := &http.Server{Addr:fmt.Sprintf(":%d", port), Handler: mux}
httpServer := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: mux}
httpServers = append(httpServers, httpServer)
go func() { httpServer.Serve(listener) }()
}

// Setup configuration.
for _, server := range *servers {
if _, err := (*servers)[0].Do(&joinCommand{Name:server.Name()}); err != nil {
if _, err := (*servers)[0].Do(&joinCommand{Name: server.Name()}); err != nil {
t.Fatal("Server unable to join: %v", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func (s *Server) followerLoop() {
// 1.Receiving valid AppendEntries RPC, or
// 2.Granting vote to candidate
if update {
timeoutChan = afterBetween(s.ElectionTimeout(), s.ElectionTimeout()*2)
timeoutChan = afterBetween(s.ElectionTimeout(), s.ElectionTimeout()*2)
}

// Exit loop on state change.
Expand Down
2 changes: 1 addition & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func TestServerMultiNode(t *testing.T) {
}
mutex.RUnlock()

for i := 0; i < 200000; i++ {
for i := 0; i < 20; i++ {
retry := 0
fmt.Println("Round ", i)

Expand Down

0 comments on commit 5e71312

Please sign in to comment.