lax timing

This commit is contained in:
Alex Dadgar
2017-10-19 17:13:27 -07:00
parent c307834765
commit 8b4c4df8b3

View File

@@ -88,7 +88,7 @@ func TestResetHeartbeatTimerLocked_Renew(t *testing.T) {
testutil.WaitForLeader(t, s1.RPC)
s1.heartbeatTimersLock.Lock()
s1.resetHeartbeatTimerLocked("foo", 5*time.Millisecond)
s1.resetHeartbeatTimerLocked("foo", 30*time.Millisecond)
s1.heartbeatTimersLock.Unlock()
if _, ok := s1.heartbeatTimers["foo"]; !ok {
@@ -99,23 +99,23 @@ func TestResetHeartbeatTimerLocked_Renew(t *testing.T) {
// Renew the heartbeat
s1.heartbeatTimersLock.Lock()
s1.resetHeartbeatTimerLocked("foo", 5*time.Millisecond)
s1.resetHeartbeatTimerLocked("foo", 30*time.Millisecond)
s1.heartbeatTimersLock.Unlock()
renew := time.Now()
// Watch for invalidation
for time.Now().Sub(renew) < time.Duration(testutil.TestMultiplier()*20)*time.Millisecond {
for time.Now().Sub(renew) < time.Duration(testutil.TestMultiplier()*100)*time.Millisecond {
s1.heartbeatTimersLock.Lock()
_, ok := s1.heartbeatTimers["foo"]
s1.heartbeatTimersLock.Unlock()
if !ok {
end := time.Now()
if diff := end.Sub(renew); diff < 5*time.Millisecond {
if diff := end.Sub(renew); diff < 30*time.Millisecond {
t.Fatalf("early invalidate %v", diff)
}
return
}
time.Sleep(time.Millisecond)
time.Sleep(2 * time.Millisecond)
}
t.Fatalf("should have expired")
}