Skip to content

Commit

Permalink
Merge pull request #458 from hashicorp/dnephin/fix-flaky-test-1
Browse files Browse the repository at this point in the history
Fix flaky TestRaft_LeadershipTransferLeaderRejectsClientRequests
  • Loading branch information
dnephin committed Apr 12, 2021
2 parents 62cc4fc + 6e151e7 commit fd170b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
5 changes: 1 addition & 4 deletions raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,7 @@ func (r *Raft) setLeadershipTransferInProgress(v bool) {

func (r *Raft) getLeadershipTransferInProgress() bool {
v := atomic.LoadInt32(&r.leaderState.leadershipTransferInProgress)
if v == 1 {
return true
}
return false
return v == 1
}

func (r *Raft) setupLeaderState() {
Expand Down
16 changes: 8 additions & 8 deletions raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestRaft_RecoverCluster(t *testing.T) {
// snapshot + log scenarios. By sweeping through the trailing logs value
// we will also hit the case where we have a snapshot only.
var err error
runRecover := func(applies int) {
runRecover := func(t *testing.T, applies int) {
conf := inmemConfig(t)
conf.TrailingLogs = 10
c := MakeCluster(3, t, conf)
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestRaft_RecoverCluster(t *testing.T) {
}
for applies := 0; applies < 20; applies++ {
t.Run(fmt.Sprintf("%d applies", applies), func(t *testing.T) {
runRecover(applies)
runRecover(t, applies)
})
}
}
Expand Down Expand Up @@ -2059,18 +2059,18 @@ func TestRaft_LeadershipTransferLeaderRejectsClientRequests(t *testing.T) {
l.requestConfigChange(configurationChangeRequest{}, 100*time.Millisecond),
}
futures = append(futures, l.LeadershipTransfer())
select {
case <-l.leadershipTransferCh:
default:
}

futures = append(futures, l.LeadershipTransferToServer(ServerID(""), ServerAddress("")))

for i, f := range futures {
t.Logf("waiting on future %v", i)
if f.Error() != ErrLeadershipTransferInProgress {
t.Errorf("case %d: should have errored with: %s, instead of %s", i, ErrLeadershipTransferInProgress, f.Error())
}
}

f := l.LeadershipTransferToServer(ServerID(""), ServerAddress(""))
if f.Error() != ErrLeadershipTransferInProgress {
t.Errorf("should have errored with: %s, instead of %s", ErrLeadershipTransferInProgress, f.Error())
}
}

func TestRaft_LeadershipTransferLeaderReplicationTimeout(t *testing.T) {
Expand Down

0 comments on commit fd170b8

Please sign in to comment.