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‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
'use strict';
22

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

‎test/parallel/test-freelist.js‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
// Flags: --expose-internals
4+
5+
constassert=require('assert');
6+
constfreelist=require('freelist');
7+
constinternalFreelist=require('internal/freelist');
8+
9+
assert.equal(typeoffreelist,'object');
10+
assert.equal(typeoffreelist.FreeList,'function');
11+
assert.strictEqual(freelist,internalFreelist);
12+
13+
constflist1=newfreelist.FreeList('flist1',3,String);
14+
15+
// Allocating when empty, should not change the list size
16+
varresult=flist1.alloc('test');
17+
assert.strictEqual(typeofresult,'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)