-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathclose.js
54 lines (48 loc) · 1.41 KB
/
close.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
const assert = require('assert')
const Cursor = require('../')
const pg = require('pg')
const text = 'SELECT generate_series as num FROM generate_series(0, 50)'
describe('close', function () {
beforeEach(function (done) {
const client = (this.client = new pg.Client())
client.connect(done)
})
this.afterEach(function (done) {
this.client.end(done)
})
it('can close a finished cursor without a callback', function (done) {
const cursor = new Cursor(text)
this.client.query(cursor)
this.client.query('SELECT NOW()', done)
cursor.read(100, function (err) {
assert.ifError(err)
cursor.close()
})
})
it('closes cursor early', function (done) {
const cursor = new Cursor(text)
this.client.query(cursor)
this.client.query('SELECT NOW()', done)
cursor.read(25, function (err) {
assert.ifError(err)
cursor.close()
})
})
it('works with callback style', function (done) {
const cursor = new Cursor(text)
const client = this.client
client.query(cursor)
cursor.read(25, function (err, rows) {
assert.ifError(err)
assert.strictEqual(rows.length, 25)
cursor.close(function (err) {
assert.ifError(err)
client.query('SELECT NOW()', done)
})
})
})
it('is a no-op to "close" the cursor before submitting it', function (done) {
const cursor = new Cursor(text)
cursor.close(done)
})
})