HTTP Transporter fixes.

pull/820/head
Ben Johnson 2013-07-08 21:00:14 -06:00
parent 4ee205422c
commit 5e713120bf
4 changed files with 9 additions and 11 deletions

View File

@ -16,7 +16,7 @@ const (
Trace = 2
)
var LogLevel int = Trace //0
var LogLevel int = 0
var logger *log.Logger
func init() {

View File

@ -5,8 +5,8 @@ import (
"net"
"net/http"
"sync"
"time"
"testing"
"time"
)
//------------------------------------------------------------------------------
@ -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())
}
@ -43,7 +42,6 @@ func TestHTTPTransporter(t *testing.T) {
runTestHttpServers(t, &servers, transporter, f0, f1, f2)
}
//------------------------------------------------------------------------------
//
// Helper Functions
@ -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)
@ -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)
}
}

View File

@ -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.

View File

@ -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)