Skip to content

Improve purge address of the Pool routine #995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/bolt-connection/src/pool/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,18 @@ class Pool {

async _purgeKey (key) {
const pool = this._pools[key]
const destructionList = []
if (pool) {
while (pool.length) {
const resource = pool.pop()
if (this._removeIdleObserver) {
this._removeIdleObserver(resource)
}
await this._destroy(resource)
destructionList.push(this._destroy(resource))
}
pool.close()
delete this._pools[key]
await Promise.all(destructionList)
}
}

Expand Down
39 changes: 38 additions & 1 deletion packages/bolt-connection/test/pool/pool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ describe('#unit Pool', () => {
expect(resource2.observer).toBeFalsy()
})

it('should thrown aquisition timeout exception if resource takes longer to be created', async () => {
it('should thrown acquisition timeout exception if resource takes longer to be created', async () => {
const address = ServerAddress.fromUrl('bolt://localhost:7687')
const acquisitionTimeout = 1000
let counter = 0
Expand Down Expand Up @@ -911,6 +911,43 @@ describe('#unit Pool', () => {
expect(counter).toEqual(1)
}
})

it('should purge resources in parallel', async () => {
const address = ServerAddress.fromUrl('bolt://localhost:7687')
let resourceCount = 0
const resourcesReleased = []
let resolveRelease
const releasePromise = new Promise((resolve) => {
resolveRelease = resolve
})

const pool = new Pool({
create: (server, release) =>
Promise.resolve(new Resource(server, resourceCount++, release)),
destroy: res => {
resourcesReleased.push(res)
resourceCount--
// Only destroy when the last resource
// get destroyed
if (resourceCount === 0) {
resolveRelease()
}
return releasePromise
},
validate: res => true
})

const resource1 = await pool.acquire(address)
const resource2 = await pool.acquire(address)
await resource1.close()
await resource2.close()

await pool.purge(address)

expect(resourcesReleased).toEqual([
resource2, resource1
])
})
})

function expectNoPendingAcquisitionRequests (pool) {
Expand Down
2 changes: 1 addition & 1 deletion packages/neo4j-driver/test/temporal-types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ describe('#integration temporal-types', () => {
await testSendAndReceiveRandomTemporalValues(() => randomLocalDateTime())
}, 60000)

it('should send and receive random LocalDateTime', async () => {
it('should send and receive array of random LocalDateTime', async () => {
if (neo4jDoesNotSupportTemporalTypes()) {
return
}
Expand Down