session
session copied to clipboard
Potential bug in unit test for idGenerator
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
Issue
https://github.com/fastify/session/blob/master/test/idGenerator.test.js
Both tests appear to have the same error - they are not using Set.add() to add the newly generated ID to the set so ids.has(id) is checking for the id in an empty Set.
const ids = new Set()
for (let i = 0; i < (cacheSize); ++i) {
const id = idGen()
if (ids.has(id)) {
t.fail('had a collision')
}
t.equal(id.length, 32)
}
I believe this should be: -
const ids = new Set()
for (let i = 0; i < (cacheSize); ++i) {
const id = idGen()
if (ids.has(id)) {
t.fail('had a collision')
}
t.equal(id.length, 32)
ids.add(id) <--------------------------------------------
}
Good catch
Thanks for reporting! Would you like to send a Pull Request to address this issue?