1717 * limitations under the License.
1818 */
1919
20- import Pool from '../../../bolt-connection/lib /pool/pool'
21- import PoolConfig from '../../../bolt-connection/lib /pool/pool-config'
20+ import Pool from '../../src /pool/pool'
21+ import PoolConfig from '../../src /pool/pool-config'
2222import { newError , error , internal } from 'neo4j-driver-core'
2323
2424const {
@@ -27,7 +27,7 @@ const {
2727
2828const { SERVICE_UNAVAILABLE } = error
2929
30- describe ( '#unit Pool' , async ( ) => {
30+ describe ( '#unit Pool' , ( ) => {
3131 it ( 'allocates if pool is empty' , async ( ) => {
3232 // Given
3333 let counter = 0
@@ -237,6 +237,44 @@ describe('#unit Pool', async () => {
237237 expect ( r0 . destroyed ) . toBeTruthy ( )
238238 } )
239239
240+ it ( 'destroys resource when pool is purged even if a new pool is created for the same address' , async ( ) => {
241+ let counter = 0
242+ const address = ServerAddress . fromUrl ( 'bolt://localhost:7687' )
243+ const pool = new Pool ( {
244+ create : ( server , release ) =>
245+ Promise . resolve ( new Resource ( server , counter ++ , release ) ) ,
246+ destroy : res => {
247+ res . destroyed = true
248+ return Promise . resolve ( )
249+ }
250+ } )
251+
252+ // Acquire resource
253+ const r0 = await pool . acquire ( address )
254+ expect ( pool . has ( address ) ) . toBeTruthy ( )
255+ expect ( r0 . id ) . toEqual ( 0 )
256+
257+ // Purging the key
258+ await pool . purge ( address )
259+ expect ( pool . has ( address ) ) . toBeFalsy ( )
260+ expect ( r0 . destroyed ) . toBeFalsy ( )
261+
262+ // Acquiring second resource should recreate the pool
263+ const r1 = await pool . acquire ( address )
264+ expect ( pool . has ( address ) ) . toBeTruthy ( )
265+ expect ( r1 . id ) . toEqual ( 1 )
266+
267+ // Closing the first resource should destroy it
268+ await r0 . close ( )
269+ expect ( pool . has ( address ) ) . toBeTruthy ( )
270+ expect ( r0 . destroyed ) . toBeTruthy ( )
271+
272+ // Closing the second resource should not destroy it
273+ await r1 . close ( )
274+ expect ( pool . has ( address ) ) . toBeTruthy ( )
275+ expect ( r1 . destroyed ) . toBeFalsy ( )
276+ } )
277+
240278 it ( 'close purges all keys' , async ( ) => {
241279 let counter = 0
242280
@@ -282,11 +320,9 @@ describe('#unit Pool', async () => {
282320 // Close the pool
283321 await pool . close ( )
284322
285- await expectAsync ( pool . acquire ( address ) ) . toBeRejectedWith (
286- jasmine . objectContaining ( {
287- message : jasmine . stringMatching ( / P o o l i s c l o s e d / )
288- } )
289- )
323+ await expect ( pool . acquire ( address ) ) . rejects . toMatchObject ( {
324+ message : expect . stringMatching ( 'Pool is closed' )
325+ } )
290326 } )
291327
292328 it ( 'should fail to acquire when closed with idle connections' , async ( ) => {
@@ -307,11 +343,9 @@ describe('#unit Pool', async () => {
307343 // Close the pool
308344 await pool . close ( )
309345
310- await expectAsync ( pool . acquire ( address ) ) . toBeRejectedWith (
311- jasmine . objectContaining ( {
312- message : jasmine . stringMatching ( / P o o l i s c l o s e d / )
313- } )
314- )
346+ await expect ( pool . acquire ( address ) ) . rejects . toMatchObject ( {
347+ message : expect . stringMatching ( 'Pool is closed' )
348+ } )
315349 } )
316350 it ( 'purges keys other than the ones to keep' , async ( ) => {
317351 let counter = 0
@@ -561,9 +595,9 @@ describe('#unit Pool', async () => {
561595 await pool . acquire ( address )
562596 await pool . acquire ( address )
563597
564- await expectAsync ( pool . acquire ( address ) ) . toBeRejectedWith (
565- jasmine . stringMatching ( 'acquisition timed out' )
566- )
598+ await expect ( pool . acquire ( address ) ) . rejects . toMatchObject ( {
599+ message : expect . stringMatching ( 'acquisition timed out' )
600+ } )
567601 expectNumberOfAcquisitionRequests ( pool , address , 0 )
568602 } )
569603
@@ -607,11 +641,11 @@ describe('#unit Pool', async () => {
607641
608642 // Let's fulfill the connect promise belonging to the first request.
609643 conns [ 0 ] . resolve ( conns [ 0 ] )
610- await expectAsync ( req1 ) . toBeResolved ( )
644+ await expect ( req1 ) . resolves . toBeDefined ( )
611645
612646 // Release the connection, it should be picked up by the second request.
613647 conns [ 0 ] . release ( address , conns [ 0 ] )
614- await expectAsync ( req2 ) . toBeResolved ( )
648+ await expect ( req2 ) . resolves . toBeDefined ( )
615649
616650 // Just to make sure that there hasn't been any new connection.
617651 expect ( conns . length ) . toEqual ( 1 )
0 commit comments