-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
270 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ package-lock.json | |
dist | ||
.DS_Store | ||
.vscode/ | ||
manually-test-on-heroku.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
"useWorkspaces": true, | ||
"version": "independent", | ||
"ignoreChanges": [ | ||
"**/*.md" | ||
"**/*.md", | ||
"**/test/**" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const Pool = require('../') | ||
|
||
const expect = require('expect.js') | ||
const net = require('net') | ||
|
||
describe('releasing clients', () => { | ||
it('removes a client which cannot be queried', async () => { | ||
// make a pool w/ only 1 client | ||
const pool = new Pool({ max: 1 }) | ||
expect(pool.totalCount).to.eql(0) | ||
const client = await pool.connect() | ||
expect(pool.totalCount).to.eql(1) | ||
expect(pool.idleCount).to.eql(0) | ||
// reach into the client and sever its connection | ||
client.connection.end() | ||
|
||
// wait for the client to error out | ||
const err = await new Promise((resolve) => client.once('error', resolve)) | ||
expect(err).to.be.ok() | ||
expect(pool.totalCount).to.eql(1) | ||
expect(pool.idleCount).to.eql(0) | ||
|
||
// try to return it to the pool - this removes it because its broken | ||
client.release() | ||
expect(pool.totalCount).to.eql(0) | ||
expect(pool.idleCount).to.eql(0) | ||
|
||
// make sure pool still works | ||
const { rows } = await pool.query('SELECT NOW()') | ||
expect(rows).to.have.length(1) | ||
await pool.end() | ||
}) | ||
|
||
it('removes a client which is ending', async () => { | ||
// make a pool w/ only 1 client | ||
const pool = new Pool({ max: 1 }) | ||
expect(pool.totalCount).to.eql(0) | ||
const client = await pool.connect() | ||
expect(pool.totalCount).to.eql(1) | ||
expect(pool.idleCount).to.eql(0) | ||
// end the client gracefully (but you shouldn't do this with pooled clients) | ||
client.end() | ||
|
||
// try to return it to the pool | ||
client.release() | ||
expect(pool.totalCount).to.eql(0) | ||
expect(pool.idleCount).to.eql(0) | ||
|
||
// make sure pool still works | ||
const { rows } = await pool.query('SELECT NOW()') | ||
expect(rows).to.have.length(1) | ||
await pool.end() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const assert = require('assert') | ||
const helper = require('./helper') | ||
const QueryStream = require('../') | ||
|
||
helper('empty-query', function (client) { | ||
it('handles empty query', function(done) { | ||
const stream = new QueryStream('-- this is a comment', []) | ||
const query = client.query(stream) | ||
query.on('end', function () { | ||
// nothing should happen for empty query | ||
done(); | ||
}).on('data', function () { | ||
// noop to kick off reading | ||
}) | ||
}) | ||
|
||
it('continues to function after stream', function (done) { | ||
client.query('SELECT NOW()', done) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.