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

lib: issuing deprecation warning for freelist #2176

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/freelist.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
'use strict';

const util = require('internal/util');

module.exports = require('internal/freelist');
util.printDeprecationMessage('freelist module is deprecated.');
33 changes: 33 additions & 0 deletions test/parallel/test-freelist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

// Flags: --expose-internals

const assert = require('assert');
const freelist = require('freelist');
const internalFreelist = require('internal/freelist');

assert.equal(typeof freelist, 'object');
assert.equal(typeof freelist.FreeList, 'function');
assert.strictEqual(freelist, internalFreelist);

const flist1 = new freelist.FreeList('flist1', 3, String);

// Allocating when empty, should not change the list size
var result = flist1.alloc('test');
assert.strictEqual(typeof result, 'string');
assert.strictEqual(result, 'test');
assert.strictEqual(flist1.list.length, 0);

// Exhaust the free list
assert(flist1.free('test1'));
assert(flist1.free('test2'));
assert(flist1.free('test3'));

// Now it should not return 'true', as max length is exceeded
assert.strictEqual(flist1.free('test4'), false);
assert.strictEqual(flist1.free('test5'), false);

// At this point 'alloc' should just return the stored values
assert.strictEqual(flist1.alloc(), 'test1');
assert.strictEqual(flist1.alloc(), 'test2');
assert.strictEqual(flist1.alloc(), 'test3');