comunicationLeap/node_modules/ws/test/BufferPool.test.js
node_modules/ws/test/BufferPool.test.jsRaw
1var BufferPool = require('../lib/BufferPool');
2require('should');
3
4describe('BufferPool', function() {
5 describe('#ctor', function() {
6 it('allocates pool', function() {
7 var db = new BufferPool(1000);
8 db.size.should.eql(1000);
9 });
10 });
11 describe('#get', function() {
12 it('grows the pool if necessary', function() {
13 var db = new BufferPool(1000);
14 var buf = db.get(2000);
15 db.size.should.be.above(1000);
16 db.used.should.eql(2000);
17 buf.length.should.eql(2000);
18 });
19 it('grows the pool after the first call, if necessary', function() {
20 var db = new BufferPool(1000);
21 var buf = db.get(1000);
22 db.used.should.eql(1000);
23 db.size.should.eql(1000);
24 buf.length.should.eql(1000);
25 var buf2 = db.get(1000);
26 db.used.should.eql(2000);
27 db.size.should.be.above(1000);
28 buf2.length.should.eql(1000);
29 });
30 it('grows the pool according to the growStrategy if necessary', function() {
31 var db = new BufferPool(1000, function(db, length) {
32 return db.size + 2345;
33 });
34 var buf = db.get(2000);
35 db.size.should.eql(3345);
36 buf.length.should.eql(2000);
37 });
38 it('doesnt grow the pool if theres enough room available', function() {
39 var db = new BufferPool(1000);
40 var buf = db.get(1000);
41 db.size.should.eql(1000);
42 buf.length.should.eql(1000);
43 });
44 });
45 describe('#reset', function() {
46 it('shinks the pool', function() {
47 var db = new BufferPool(1000);
48 var buf = db.get(2000);
49 db.reset(true);
50 db.size.should.eql(1000);
51 });
52 it('shrinks the pool according to the shrinkStrategy', function() {
53 var db = new BufferPool(1000, function(db, length) {
54 return db.used + length;
55 }, function(db) {
56 return 0;
57 });
58 var buf = db.get(2000);
59 db.reset(true);
60 db.size.should.eql(0);
61 });
62 });
63});