17
17
* limitations under the License.
18
18
*/
19
19
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'
22
22
import { newError , error , internal } from 'neo4j-driver-core'
23
23
24
24
const {
@@ -27,7 +27,7 @@ const {
27
27
28
28
const { SERVICE_UNAVAILABLE } = error
29
29
30
- describe ( '#unit Pool' , async ( ) => {
30
+ describe ( '#unit Pool' , ( ) => {
31
31
it ( 'allocates if pool is empty' , async ( ) => {
32
32
// Given
33
33
let counter = 0
@@ -237,6 +237,44 @@ describe('#unit Pool', async () => {
237
237
expect ( r0 . destroyed ) . toBeTruthy ( )
238
238
} )
239
239
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
+
240
278
it ( 'close purges all keys' , async ( ) => {
241
279
let counter = 0
242
280
@@ -282,11 +320,9 @@ describe('#unit Pool', async () => {
282
320
// Close the pool
283
321
await pool . close ( )
284
322
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
+ } )
290
326
} )
291
327
292
328
it ( 'should fail to acquire when closed with idle connections' , async ( ) => {
@@ -307,11 +343,9 @@ describe('#unit Pool', async () => {
307
343
// Close the pool
308
344
await pool . close ( )
309
345
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
+ } )
315
349
} )
316
350
it ( 'purges keys other than the ones to keep' , async ( ) => {
317
351
let counter = 0
@@ -561,9 +595,9 @@ describe('#unit Pool', async () => {
561
595
await pool . acquire ( address )
562
596
await pool . acquire ( address )
563
597
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
+ } )
567
601
expectNumberOfAcquisitionRequests ( pool , address , 0 )
568
602
} )
569
603
@@ -607,11 +641,11 @@ describe('#unit Pool', async () => {
607
641
608
642
// Let's fulfill the connect promise belonging to the first request.
609
643
conns [ 0 ] . resolve ( conns [ 0 ] )
610
- await expectAsync ( req1 ) . toBeResolved ( )
644
+ await expect ( req1 ) . resolves . toBeDefined ( )
611
645
612
646
// Release the connection, it should be picked up by the second request.
613
647
conns [ 0 ] . release ( address , conns [ 0 ] )
614
- await expectAsync ( req2 ) . toBeResolved ( )
648
+ await expect ( req2 ) . resolves . toBeDefined ( )
615
649
616
650
// Just to make sure that there hasn't been any new connection.
617
651
expect ( conns . length ) . toEqual ( 1 )
0 commit comments