File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ class PgQueryStream extends Readable {
23
23
24
24
_destroy ( _err , cb ) {
25
25
this . cursor . close ( ( err ) => {
26
- cb && cb ( err || _err )
26
+ cb ( err || _err )
27
27
} )
28
28
}
29
29
Original file line number Diff line number Diff line change @@ -45,6 +45,21 @@ helper('early close', function (client) {
45
45
} , 100 )
46
46
} )
47
47
48
+ it ( 'emits an error when calling destroy with an error' , function ( done ) {
49
+ var stream = new QueryStream ( 'SELECT * FROM generate_series(0, 100), pg_sleep(1)' )
50
+ client . query ( stream )
51
+ stream . on ( 'data' , ( ) => done ( new Error ( 'stream should not have returned rows' ) ) )
52
+ setTimeout ( ( ) => {
53
+ stream . destroy ( new Error ( 'intentional error' ) )
54
+ stream . on ( 'error' , ( err ) => {
55
+ // make sure there's an error
56
+ assert ( err ) ;
57
+ assert . strictEqual ( err . message , 'intentional error' ) ;
58
+ done ( ) ;
59
+ } )
60
+ } , 100 )
61
+ } )
62
+
48
63
it ( 'can destroy stream while reading an error' , function ( done ) {
49
64
var stream = new QueryStream ( 'SELECT * from pg_sleep(1), basdfasdf;' )
50
65
client . query ( stream )
You can’t perform that action at this time.
0 commit comments