Skip to content

Commit 5eaad2f

Browse files
committed
Add failing test for destroying unsubmitted stream
1 parent 7875c48 commit 5eaad2f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/pg-query-stream/test/close.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ helper('early close', function (client) {
6161
})
6262

6363
it('can destroy stream while reading an error', function (done) {
64-
var stream = new QueryStream('SELECT * from pg_sleep(1), basdfasdf;')
64+
var stream = new QueryStream('SELECT * from pg_sleep(1), basdfasdf;')
6565
client.query(stream)
6666
stream.on('data', () => done(new Error('stream should not have returned rows')))
6767
stream.once('error', () => {
@@ -70,4 +70,19 @@ helper('early close', function (client) {
7070
setTimeout(done, 100)
7171
})
7272
})
73+
74+
it('does not crash when destroying the stream immediately after calling read', function (done) {
75+
var stream = new QueryStream('SELECT * from generate_series(0, 100), pg_sleep(1);')
76+
client.query(stream)
77+
stream.on('data', () => done(new Error('stream should not have returned rows')))
78+
stream.destroy()
79+
stream.on('close', done)
80+
})
81+
82+
it('does not crash when destroying the stream before its submitted', function (done) {
83+
var stream = new QueryStream('SELECT * from generate_series(0, 100), pg_sleep(1);')
84+
stream.on('data', () => done(new Error('stream should not have returned rows')))
85+
stream.destroy()
86+
stream.on('close', done)
87+
})
7388
})

0 commit comments

Comments
 (0)