Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential bug in unit test for idGenerator #266

Open
2 tasks done
U-4-E-A opened this issue Sep 9, 2024 · 2 comments
Open
2 tasks done

Potential bug in unit test for idGenerator #266

U-4-E-A opened this issue Sep 9, 2024 · 2 comments
Labels
good first issue Good for newcomers

Comments

@U-4-E-A
Copy link

U-4-E-A commented Sep 9, 2024

Prerequisites

  • I have written a descriptive issue title
  • 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) <--------------------------------------------
}
@climba03003 climba03003 added the good first issue Good for newcomers label Sep 9, 2024
@climba03003
Copy link
Member

Good catch

@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants