fix fakelag double-rate issue

Basically, fakelag was counting the time imposed by its own sleeps as though
the user had themselves paused for that amount of time. Therefore, if a user
sent a large number of consecutive commands, every other command would pause
for the expected throttle interval, but the subsequent command would be
processed instantly (you'd get two back-to-back commands). This resulted in
throttled users being able to send at double the expected rate.
This commit is contained in:
Shivaram Lingamneni 2018-04-16 04:30:01 -04:00
parent c75d2c91c5
commit f6d2dade4e
2 changed files with 8 additions and 5 deletions

View file

@ -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)