Skip to content

Assertion randomly fails #5

@yanickrochon

Description

@yanickrochon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions