diff --git a/server.go b/server.go index 85214d22ce..3c96409ab5 100644 --- a/server.go +++ b/server.go @@ -67,7 +67,6 @@ type Server interface { LogPath() string SnapshotPath(lastIndex uint64, lastTerm uint64) string Term() uint64 - setTerm(term uint64) CommitIndex() uint64 VotedFor() string MemberCount() int @@ -260,13 +259,6 @@ func (s *server) Term() uint64 { return s.currentTerm } -// Set the current term of the server, for testing purpose. -func (s *server) setTerm(term uint64) { - s.mutex.Lock() - defer s.mutex.Unlock() - s.currentTerm = term -} - // Retrieves the current commit index of the server. func (s *server) CommitIndex() uint64 { s.log.mutex.RLock() diff --git a/server_test.go b/server_test.go index c9d8f38df1..f8be91e5f8 100644 --- a/server_test.go +++ b/server_test.go @@ -45,7 +45,10 @@ func TestServerRequestVoteDeniedForStaleTerm(t *testing.T) { t.Fatalf("Server %s unable to join: %v", s.Name(), err) } - s.(*server).setTerm(2) + s.(*server).mutex.Lock() + s.(*server).currentTerm = 2 + s.(*server).mutex.Unlock() + defer s.Stop() resp := s.RequestVote(newRequestVoteRequest(1, "foo", 1, 0)) if resp.Term != 2 || resp.VoteGranted { @@ -65,7 +68,9 @@ func TestServerRequestVoteDeniedIfAlreadyVoted(t *testing.T) { t.Fatalf("Server %s unable to join: %v", s.Name(), err) } - s.(*server).setTerm(2) + s.(*server).mutex.Lock() + s.(*server).currentTerm = 2 + s.(*server).mutex.Unlock() defer s.Stop() resp := s.RequestVote(newRequestVoteRequest(2, "foo", 1, 0)) if resp.Term != 2 || !resp.VoteGranted { @@ -88,7 +93,9 @@ func TestServerRequestVoteApprovedIfAlreadyVotedInOlderTerm(t *testing.T) { time.Sleep(time.Millisecond * 100) - s.(*server).setTerm(2) + s.(*server).mutex.Lock() + s.(*server).currentTerm = 2 + s.(*server).mutex.Unlock() defer s.Stop() resp := s.RequestVote(newRequestVoteRequest(2, "foo", 2, 1)) if resp.Term != 2 || !resp.VoteGranted || s.VotedFor() != "foo" { @@ -236,7 +243,9 @@ func TestServerAppendEntriesWithStaleTermsAreRejected(t *testing.T) { s.Start() defer s.Stop() - s.(*server).setTerm(2) + s.(*server).mutex.Lock() + s.(*server).currentTerm = 2 + s.(*server).mutex.Unlock() // Append single entry. e, _ := newLogEntry(nil, 1, 1, &testCommand1{Val: "foo", I: 10})