Skip to content

Commit fef87fe

Browse files
thefourtheyeTrott
authored andcommitted
lib,test: add freelist deprecation and test
As per the dicussion in #569, this patch issues a deprecation warning when freelist module is required. A test file for freelist is also added. PR-URL: #2176 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Brendan Ashworth <[email protected]>
1 parent a764ac4 commit fef87fe

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/freelist.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
'use strict';
22

3+
const util = require('internal/util');
4+
35
module.exports = require('internal/freelist');
6+
util.printDeprecationMessage('freelist module is deprecated.');

test/parallel/test-freelist.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
// Flags: --expose-internals
4+
5+
const assert = require('assert');
6+
const freelist = require('freelist');
7+
const internalFreelist = require('internal/freelist');
8+
9+
assert.equal(typeof freelist, 'object');
10+
assert.equal(typeof freelist.FreeList, 'function');
11+
assert.strictEqual(freelist, internalFreelist);
12+
13+
const flist1 = new freelist.FreeList('flist1', 3, String);
14+
15+
// Allocating when empty, should not change the list size
16+
var result = flist1.alloc('test');
17+
assert.strictEqual(typeof result, 'string');
18+
assert.strictEqual(result, 'test');
19+
assert.strictEqual(flist1.list.length, 0);
20+
21+
// Exhaust the free list
22+
assert(flist1.free('test1'));
23+
assert(flist1.free('test2'));
24+
assert(flist1.free('test3'));
25+
26+
// Now it should not return 'true', as max length is exceeded
27+
assert.strictEqual(flist1.free('test4'), false);
28+
assert.strictEqual(flist1.free('test5'), false);
29+
30+
// At this point 'alloc' should just return the stored values
31+
assert.strictEqual(flist1.alloc(), 'test1');
32+
assert.strictEqual(flist1.alloc(), 'test2');
33+
assert.strictEqual(flist1.alloc(), 'test3');

0 commit comments

Comments
 (0)