mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 16:36:15 -04:00
pad_utils: Rate limit identical warnDeprecated
calls
This commit is contained in:
parent
908175d1ca
commit
cfb68e5725
2 changed files with 32 additions and 0 deletions
|
@ -14,6 +14,7 @@ describe(__filename, function () {
|
|||
|
||||
afterEach(async function () {
|
||||
warnDeprecated.logger = backups.logger;
|
||||
delete warnDeprecated._rl; // Reset internal rate limiter state.
|
||||
});
|
||||
|
||||
it('includes the stack', async function () {
|
||||
|
@ -22,5 +23,21 @@ describe(__filename, function () {
|
|||
warnDeprecated();
|
||||
assert(got.includes(__filename));
|
||||
});
|
||||
|
||||
it('rate limited', async function () {
|
||||
let got = 0;
|
||||
warnDeprecated.logger = {warn: () => ++got};
|
||||
warnDeprecated(); // Initialize internal rate limiter state.
|
||||
const {period} = warnDeprecated._rl;
|
||||
got = 0;
|
||||
const testCases = [[0, 1], [0, 1], [period - 1, 1], [period, 2]];
|
||||
for (const [now, want] of testCases) { // In a loop so that the stack trace is the same.
|
||||
warnDeprecated._rl.now = () => now;
|
||||
warnDeprecated();
|
||||
assert.equal(got, want);
|
||||
}
|
||||
warnDeprecated(); // Should have a different stack trace.
|
||||
assert.equal(got, testCases[testCases.length - 1][1] + 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue