-
-
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.
Merge branch 'brianc:master' into master
- Loading branch information
Showing
17 changed files
with
215 additions
and
50 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
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,51 @@ | ||
const assert = require('assert') | ||
const Cursor = require('../') | ||
const pg = require('pg') | ||
|
||
const text = 'SELECT generate_series as num FROM generate_series(0, 5)' | ||
|
||
describe('cursor using promises', function () { | ||
beforeEach(function (done) { | ||
const client = (this.client = new pg.Client()) | ||
client.connect(done) | ||
|
||
this.pgCursor = function (text, values) { | ||
return client.query(new Cursor(text, values || [])) | ||
} | ||
}) | ||
|
||
afterEach(function () { | ||
this.client.end() | ||
}) | ||
|
||
it('resolve with result', async function () { | ||
const cursor = this.pgCursor(text) | ||
const res = await cursor.read(6) | ||
assert.strictEqual(res.length, 6) | ||
}) | ||
|
||
it('reject with error', function (done) { | ||
const cursor = this.pgCursor('select asdfasdf') | ||
cursor.read(1).catch((err) => { | ||
assert(err) | ||
done() | ||
}) | ||
}) | ||
|
||
it('read multiple times', async function () { | ||
const cursor = this.pgCursor(text) | ||
let res | ||
|
||
res = await cursor.read(2) | ||
assert.strictEqual(res.length, 2) | ||
|
||
res = await cursor.read(3) | ||
assert.strictEqual(res.length, 3) | ||
|
||
res = await cursor.read(1) | ||
assert.strictEqual(res.length, 1) | ||
|
||
res = await cursor.read(1) | ||
assert.strictEqual(res.length, 0) | ||
}) | ||
}) |
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,16 @@ | ||
// This test is meant to be spawned from idle-timeout.js | ||
if (module === require.main) { | ||
const allowExitOnIdle = process.env.ALLOW_EXIT_ON_IDLE === '1' | ||
const Pool = require('../index') | ||
|
||
const pool = new Pool({ idleTimeoutMillis: 200, ...(allowExitOnIdle ? { allowExitOnIdle: true } : {}) }) | ||
pool.query('SELECT NOW()', (err, res) => console.log('completed first')) | ||
pool.on('remove', () => { | ||
console.log('removed') | ||
done() | ||
}) | ||
|
||
setTimeout(() => { | ||
pool.query('SELECT * from generate_series(0, 1000)', (err, res) => console.log('completed second')) | ||
}, 50) | ||
} |
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
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.