summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSakthipriyan Vairamani <thechargingvolcano@gmail.com>2015-07-14 22:53:54 +0530
committerRich Trott <rtrott@gmail.com>2015-07-17 19:48:31 -0700
commitfef87fee1de60c3d5db2652ee2004a6e78d112ff (patch)
tree4cbc5d55e84a62780fde177ecac031cc8af8366a
parenta764ac4fb7a3c9d1271b47e0c9e05799f155550c (diff)
downloadnode-new-fef87fee1de60c3d5db2652ee2004a6e78d112ff.tar.gz
lib,test: add freelist deprecation and test
As per the dicussion in https://github.com/nodejs/io.js/issues/569, this patch issues a deprecation warning when freelist module is required. A test file for freelist is also added. PR-URL: https://github.com/nodejs/io.js/pull/2176 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
-rw-r--r--lib/freelist.js3
-rw-r--r--test/parallel/test-freelist.js33
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/freelist.js b/lib/freelist.js
index 9300c11487..ad33f971eb 100644
--- a/lib/freelist.js
+++ b/lib/freelist.js
@@ -1,3 +1,6 @@
'use strict';
+const util = require('internal/util');
+
module.exports = require('internal/freelist');
+util.printDeprecationMessage('freelist module is deprecated.');
diff --git a/test/parallel/test-freelist.js b/test/parallel/test-freelist.js
new file mode 100644
index 0000000000..9a847a5f1f
--- /dev/null
+++ b/test/parallel/test-freelist.js
@@ -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');