44 * Module dependencies.
55 */
66
7+ const co = require ( 'co' ) ;
78const assert = require ( 'assert' ) ;
89const rds = require ( '../' ) ;
910const config = require ( './config' ) ;
@@ -16,6 +17,10 @@ describe('client.test.js', function () {
1617 yield this . db . query ( 'delete from ?? where name like ?' , [ table , prefix + '%' ] ) ;
1718 } ) ;
1819
20+ after ( function ( done ) {
21+ this . db . end ( done ) ;
22+ } ) ;
23+
1924 describe ( 'rds(options)' , function ( ) {
2025 it ( 'should connect rds success' , function * ( ) {
2126 let rows = yield this . db . query ( 'show tables' ) ;
@@ -820,4 +825,31 @@ describe('client.test.js', function () {
820825 assert . equal ( count , 0 ) ;
821826 } ) ;
822827 } ) ;
828+
829+ describe ( 'mock query after client end' , function ( ) {
830+ it ( 'should query throw error after end' , function * ( ) {
831+ const db = rds ( config ) ;
832+ yield db . query ( 'select * from ?? limit 10' , [ table ] ) ;
833+ yield db . end ( ) ;
834+ const db2 = rds ( config ) ;
835+
836+ try {
837+ yield db . query ( 'select * from ?? limit 10' , [ table ] ) ;
838+ throw new Error ( 'should not run this' ) ;
839+ } catch ( err ) {
840+ assert . equal ( err . message , 'Pool is closed.' ) ;
841+ }
842+
843+ yield db2 . query ( 'select * from ?? limit 10' , [ table ] ) ;
844+ yield db2 . end ( ) ;
845+ } ) ;
846+
847+ it ( 'should support end with callback style' , function ( done ) {
848+ const db = rds ( config ) ;
849+ co ( function * ( ) {
850+ yield db . query ( 'select * from ?? limit 10' , [ table ] ) ;
851+ db . end ( done ) ;
852+ } ) . catch ( done ) ;
853+ } ) ;
854+ } ) ;
823855} ) ;
0 commit comments