node/test/parallel/test-freelist.js
cjihrig b70dc67828 lib,test: remove publicly exposed freelist
The freelist module was deprecated in io.js and moved to an
internal module. This commit removes public access to freelist,
while leaving the internal module, which is still in use.

Fixes: https://github.com/nodejs/node/issues/569
PR-URL: https://github.com/nodejs/node/pull/3738
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2015-11-11 10:36:06 -05:00

33 lines
995 B
JavaScript

'use strict';
// Flags: --expose-internals
require('../common');
const assert = require('assert');
const freelist = require('internal/freelist');
assert.equal(typeof freelist, 'object');
assert.equal(typeof freelist.FreeList, 'function');
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');