@ -4,7 +4,7 @@ var gonna = require('gonna')
var _ = require ( 'lodash' )
var _ = require ( 'lodash' )
var async = require ( 'async' )
var async = require ( 'async' )
var concat = require ( 'concat-stream' )
var concat = require ( 'concat-stream' )
var pg = require ( 'pg .js ')
var pg = require ( 'pg ')
var copy = require ( '../' ) . to
var copy = require ( '../' ) . to
@ -20,11 +20,13 @@ var testConstruction = function() {
assert . equal ( stream . _readableState . highWaterMark , 10 , 'Client should have been set with a correct highWaterMark.' )
assert . equal ( stream . _readableState . highWaterMark , 10 , 'Client should have been set with a correct highWaterMark.' )
}
}
testConstruction ( )
//testConstruction()
var testRange = function ( top ) {
var testRange = function ( top ) {
var fromClient = client ( )
var fromClient = client ( )
var txt = 'COPY (SELECT * from generate_series(0, ' + ( top - 1 ) + ')) TO STDOUT'
var txt = 'COPY (SELECT * from generate_series(0, ' + ( top - 1 ) + ')) TO STDOUT'
var res ;
var stream = fromClient . query ( copy ( txt ) )
var stream = fromClient . query ( copy ( txt ) )
var done = gonna ( 'finish piping out' , 1000 , function ( ) {
var done = gonna ( 'finish piping out' , 1000 , function ( ) {
@ -32,41 +34,19 @@ var testRange = function(top) {
} )
} )
stream . pipe ( concat ( function ( buf ) {
stream . pipe ( concat ( function ( buf ) {
var res = buf . toString ( 'utf8' )
res = buf . toString ( 'utf8' )
} ) )
stream . on ( 'end' , function ( ) {
var expected = _ . range ( 0 , top ) . join ( '\n' ) + '\n'
var expected = _ . range ( 0 , top ) . join ( '\n' ) + '\n'
assert . equal ( res , expected )
assert . equal ( res , expected )
assert . equal ( stream . rowCount , top , 'should have rowCount ' + top + ' but got ' + stream . rowCount )
assert . equal ( stream . rowCount , top , 'should have rowCount ' + top + ' but got ' + stream . rowCount )
done ( )
done ( )
} ) )
} ) ;
}
}
testRange ( 10000 )
testRange ( 10000 )
var testLeak = function ( rounds ) {
var fromClient = client ( )
var txt = 'COPY (SELECT 10) TO STDOUT'
var runStream = function ( num , callback ) {
var stream = fromClient . query ( copy ( txt ) )
stream . on ( 'data' , function ( data ) {
// Just throw away the data.
} )
stream . on ( 'end' , callback )
stream . on ( 'error' , callback )
}
async . timesSeries ( rounds , runStream , function ( err ) {
assert . equal ( err , null )
assert . equal ( fromClient . connection . stream . listeners ( 'close' ) . length , 0 )
assert . equal ( fromClient . connection . stream . listeners ( 'data' ) . length , 1 )
assert . equal ( fromClient . connection . stream . listeners ( 'end' ) . length , 2 )
assert . equal ( fromClient . connection . stream . listeners ( 'error' ) . length , 1 )
fromClient . end ( )
} )
}
testLeak ( 5 )
var testInternalPostgresError = function ( ) {
var testInternalPostgresError = function ( ) {
var cancelClient = client ( )
var cancelClient = client ( )
var queryClient = client ( )
var queryClient = client ( )
@ -94,4 +74,4 @@ var testInternalPostgresError = function() {
} )
} )
}
}
testInternalPostgresError ( )
//testInternalPostgresError()