Skip to content

Commit

Permalink
consul: improve test reliability for session ttls
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanuber committed Jan 10, 2015
1 parent 5bf1abf commit 757c850
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions consul/session_ttl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,19 +352,24 @@ func TestServer_SessionTTL_Failover(t *testing.T) {
}

// Find the new leader
time.Sleep(200 * time.Millisecond)
leader = nil
for _, s := range servers {
if s.IsLeader() {
leader = s
testutil.WaitForResult(func() (bool, error) {
leader = nil
for _, s := range servers {
if s.IsLeader() {
leader = s
}
}
if leader == nil {
return false, fmt.Errorf("Should have a new leader")
}
}
if leader == nil {
t.Fatalf("Should have a new leader")
}

// Ensure session timer is restored
if _, ok := leader.sessionTimers[id1]; !ok {
t.Fatalf("missing session timer")
}
// Ensure session timer is restored
if _, ok := leader.sessionTimers[id1]; !ok {
return false, fmt.Errorf("missing session timer")
}

return true, nil
}, func(err error) {
t.Fatalf("err: %s", err)
})
}

0 comments on commit 757c850

Please sign in to comment.