Performance: Automate clean up of old material after hitting a limit in libsignal-protocol

This commit is contained in:
Fedor Indutny
2021-04-13 08:52:26 -07:00
committed by GitHub
parent 62f1a42c25
commit d933e3a6fe
2 changed files with 57 additions and 2 deletions

View File

@@ -105,4 +105,32 @@ describe('Protocol Wrapper', function protocolWrapperDescribe() {
});
});
});
describe('cleanOldMessageKeys', () => {
it('should clean old message keys', () => {
const messageKeys = {};
const LIMIT = 2000;
for (let i = 0; i < 2 * LIMIT; i += 1) {
messageKeys[i] = i;
}
libsignal.SessionCipher.cleanOldMessageKeys(messageKeys);
for (let i = 0; i < LIMIT; i += 1) {
assert(
!Object.prototype.hasOwnProperty.call(messageKeys, i),
`should delete old key ${i}`
);
}
for (let i = LIMIT; i < 2 * LIMIT; i += 1) {
assert(
Object.prototype.hasOwnProperty.call(messageKeys, i),
`should have fresh key ${i}`
);
}
});
});
});