node-postgres/test/integration/connection-pool/yield-support-body.js
Brian C b1b2801c71 Add onFailure to query#then (#1082)
The promise adapter I had implemented wasn't spec compliant: it didn't accept both `onSuccess` and `onFailure` in the call to `query#then`.  This subtly broke yield & async/await because they both rely on `onError` being passed into `Promise#then`.  The pool was also not returning the promise after a client was acquired, which broke awaiting on `pool.connect` - this is also fixed now.
2016-07-19 10:16:48 -05:00

29 lines
579 B
JavaScript

var helper = require('./test-helper')
var co = require('co')
var tid = setTimeout(function() {
throw new Error('Tests did not complete in tme')
}, 1000)
co(function * () {
var client = yield helper.pg.connect()
var res = yield client.query('SELECT $1::text as name', ['foo'])
assert.equal(res.rows[0].name, 'foo')
var threw = false
try {
yield client.query('SELECT LKDSJDSLKFJ')
} catch(e) {
threw = true
}
assert(threw)
client.release()
helper.pg.end()
clearTimeout(tid)
})
.catch(function(e) {
setImmediate(function() {
throw e
})
})