-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
error-handling.js
86 lines (81 loc) · 2.37 KB
/
error-handling.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict'
const assert = require('assert')
const Cursor = require('../')
const pg = require('pg')
const text = 'SELECT generate_series as num FROM generate_series(0, 4)'
describe('error handling', function() {
it('can continue after error', function(done) {
const client = new pg.Client()
client.connect()
const cursor = client.query(new Cursor('asdfdffsdf'))
cursor.read(1, function(err) {
assert(err)
client.query('SELECT NOW()', function(err) {
assert.ifError(err)
client.end()
done()
})
})
})
})
describe('read callback does not fire sync', () => {
it('does not fire error callback sync', done => {
const client = new pg.Client()
client.connect()
const cursor = client.query(new Cursor('asdfdffsdf'))
let after = false
cursor.read(1, function(err) {
assert(err, 'error should be returned')
assert.strictEqual(after, true, 'should not call read sync')
after = false
cursor.read(1, function(err) {
assert(err, 'error should be returned')
assert.strictEqual(after, true, 'should not call read sync')
client.end()
done()
})
after = true
})
after = true
})
it('does not fire result sync after finished', done => {
const client = new pg.Client()
client.connect()
const cursor = client.query(new Cursor('SELECT NOW()'))
let after = false
cursor.read(1, function(err) {
assert(!err)
assert.strictEqual(after, true, 'should not call read sync')
cursor.read(1, function(err) {
assert(!err)
after = false
cursor.read(1, function(err) {
assert(!err)
assert.strictEqual(after, true, 'should not call read sync')
client.end()
done()
})
after = true
})
})
after = true
})
})
describe('proper cleanup', function() {
it('can issue multiple cursors on one client', function(done) {
const client = new pg.Client()
client.connect()
const cursor1 = client.query(new Cursor(text))
cursor1.read(8, function(err, rows) {
assert.ifError(err)
assert.strictEqual(rows.length, 5)
const cursor2 = client.query(new Cursor(text))
cursor2.read(8, function(err, rows) {
assert.ifError(err)
assert.strictEqual(rows.length, 5)
client.end()
done()
})
})
})
})