From 5e713120bf67d8ae3c17a09d6bdacda38179e0d9 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Mon, 8 Jul 2013 21:00:14 -0600 Subject: [PATCH] HTTP Transporter fixes. --- debug.go | 2 +- http_transporter_test.go | 14 ++++++-------- server.go | 2 +- server_test.go | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/debug.go b/debug.go index 8ffafdab83..130a7b0a39 100644 --- a/debug.go +++ b/debug.go @@ -16,7 +16,7 @@ const ( Trace = 2 ) -var LogLevel int = Trace //0 +var LogLevel int = 0 var logger *log.Logger func init() { diff --git a/http_transporter_test.go b/http_transporter_test.go index 00d23de6e6..2e06751c86 100644 --- a/http_transporter_test.go +++ b/http_transporter_test.go @@ -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) } } diff --git a/server.go b/server.go index 4e49ccf7c7..139a2b6b5b 100644 --- a/server.go +++ b/server.go @@ -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. diff --git a/server_test.go b/server_test.go index bc6b7e15f7..ac152193af 100644 --- a/server_test.go +++ b/server_test.go @@ -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)