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) <--------------------------------------------
}
Prerequisites
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 soids.has(id)
is checking for theid
in an emptySet
.I believe this should be: -