mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-26 12:42:50 +01:00
Merge pull request #244 from slingamn/fix_fakelag
fix fakelag double-rate issue
This commit is contained in:
commit
3a00b64830
@ -85,9 +85,10 @@ func (fl *Fakelag) Touch() {
|
||||
}
|
||||
// space them out by at least window/messagesperwindow
|
||||
sleepDuration := time.Duration((int64(fl.window) / int64(fl.throttleMessagesPerWindow)) - int64(elapsed))
|
||||
if sleepDuration < 0 {
|
||||
sleepDuration = 0
|
||||
if sleepDuration > 0 {
|
||||
fl.sleepFunc(sleepDuration)
|
||||
// the touch time should take into account the time we slept
|
||||
fl.lastTouch = fl.nowFunc()
|
||||
}
|
||||
fl.sleepFunc(sleepDuration)
|
||||
}
|
||||
}
|
||||
|
@ -83,13 +83,15 @@ func TestFakelag(t *testing.T) {
|
||||
t.Fatalf("incorrect sleep time: %v != %v", expected, duration)
|
||||
}
|
||||
|
||||
// send another message without a pause; we should have to sleep for 500 msec
|
||||
fl.Touch()
|
||||
if fl.state != FakelagThrottled {
|
||||
t.Fatalf("should be throttled")
|
||||
}
|
||||
slept, duration = mt.lastSleep()
|
||||
if duration != interval {
|
||||
t.Fatalf("incorrect sleep time: %v != %v", interval, duration)
|
||||
expected, _ = time.ParseDuration("500ms")
|
||||
if duration != expected {
|
||||
t.Fatalf("incorrect sleep time: %v != %v", duration, expected)
|
||||
}
|
||||
|
||||
mt.pause(interval * 6)
|
||||
|
Loading…
Reference in New Issue
Block a user