11require ( __dirname + '/test-helper' ) ;
22var utils = require ( __dirname + "/../../lib/utils" ) ;
3- var Pool = utils . Pool ;
43var defaults = require ( __dirname + "/../../lib" ) . defaults ;
54
65//this tests the monkey patching
@@ -21,101 +20,6 @@ test("EventEmitter.once", function() {
2120 assert . equal ( callCount , 1 ) ;
2221} ) ;
2322
24- test ( 'an empty pool' , function ( ) {
25- test ( 'with no creation method' , function ( ) {
26- var pool = new Pool ( 10 ) ;
27- var brian = { name :'brian' } ;
28-
29- test ( 'can set and get an item' , function ( ) {
30- pool . checkIn ( brian ) ;
31- var sync = pool . checkOut ( assert . calls ( function ( err , item ) {
32- assert . equal ( brian , item )
33- assert . same ( brian , item )
34- } ) )
35- assert . ok ( sync , "should have fired sync" )
36- } )
37-
38- test ( 'checkout blocks until item checked back in' , function ( ) {
39- var called = false ;
40- var sync = pool . checkOut ( assert . calls ( function ( err , item ) {
41- called = true ;
42- assert . equal ( brian , item )
43- assert . same ( brian , item )
44- } ) )
45- assert . ok ( sync === false , "Should not have fired sync" )
46- assert . ok ( called === false , "Should not have fired callback yet" )
47- pool . checkIn ( brian )
48- } )
49-
50- } )
51-
52- test ( 'with a creation method' , function ( ) {
53- var customName = "first" ;
54- var callCount = 0 ;
55- var pool = new Pool ( 3 , function ( ) {
56- return { name : customName + ( ++ callCount ) } ;
57- } ) ;
58-
59- test ( 'creates if pool is not at max size' , function ( ) {
60- var sync = pool . checkOut ( assert . calls ( function ( err , item ) {
61- assert . equal ( item . name , "first1" ) ;
62- } ) )
63- assert . ok ( sync , "Should have generated item & called callback in sync" )
64- } )
65-
66- test ( 'creates again if item is checked out' , function ( ) {
67- var sync = pool . checkOut ( assert . calls ( function ( err , item ) {
68- assert . equal ( item . name , "first2" )
69- } ) )
70- assert . ok ( sync , "Should have called in sync again" )
71- } )
72- var external = { name : 'boom' } ;
73- test ( 'can add another item' , function ( ) {
74- pool . checkIn ( external )
75- var sync = pool . checkOut ( assert . calls ( function ( err , item ) {
76- assert . equal ( item . name , 'boom' )
77- } ) )
78- assert . ok ( sync , "Should have fired 3rd in sync" )
79- } )
80-
81- test ( 'after pool is full, create is not called again' , function ( ) {
82- var called = false ;
83- var sync = pool . checkOut ( assert . calls ( function ( err , item ) {
84- called = true ;
85- assert . equal ( item . name , 'boom' )
86- } ) )
87- assert . ok ( sync === false , "should not be sync" )
88- assert . ok ( called === false , "should not have called callback" )
89- pool . checkIn ( external ) ;
90- } )
91- } )
92- } )
93-
94- test ( 'a pool with size of zero' , function ( ) {
95- var index = 0 ;
96- var pool = new Pool ( 0 , function ( ) {
97- return index ++ ;
98- } )
99- test ( 'checkin does nothing' , function ( ) {
100- index = 0 ;
101- pool . checkIn ( 301813 ) ;
102- assert . equal ( pool . checkOut ( assert . calls ( function ( err , item ) {
103- assert . equal ( item , 0 ) ;
104- } ) ) ) ;
105- } )
106- test ( 'always creates a new item' , function ( ) {
107- index = 0 ;
108- pool . checkOut ( assert . calls ( function ( err , item ) {
109- assert . equal ( item , 0 ) ;
110- } ) )
111- pool . checkOut ( assert . calls ( function ( err , item ) {
112- assert . equal ( item , 1 ) ;
113- } ) )
114- pool . checkOut ( assert . calls ( function ( err , item ) {
115- assert . equal ( item , 2 ) ;
116- } ) )
117- } )
118- } )
11923
12024test ( 'normalizing connection info' , function ( ) {
12125 test ( 'with objects' , function ( ) {
0 commit comments