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

Assertion randomly fails #5

Open
yanickrochon opened this issue Mar 4, 2015 · 1 comment
Open

Assertion randomly fails #5

yanickrochon opened this issue Mar 4, 2015 · 1 comment

Comments

@yanickrochon
Copy link

I ran the unit tests on the module and got a random failure in the section should renew the item's timeout on every single 'get'. The assertion is too narrow. For example, timeout + timeout * 4/3 = 233.3333...., while you check that new Date().getTime() - now = 233 should be greater. Since the value's precision is not high enough, it does not account for the 0.3333 nanoseconds, it may be greater if and only if the time required to run the test is greater than 5000 nanoseconds. This is not the case on fast computers. Therefore, the test is fails.

You should round down the value and check for "greater or equal" instead :

assert.ok(Math.floor(timeout + timeout * 4/3) <= new Date().getTime() - now);

The same thing happens for the test case should expire an item by timeout where the test

assert.ok( timeout < delta);

should be

assert.ok( timeout <= delta);

for the same reason.

@silviom
Copy link
Owner

silviom commented Mar 9, 2015

Hello, thanks for the tip. I will update it as soon I have free time to do it.
Silvio.

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

No branches or pull requests

2 participants