@@ -37,7 +37,9 @@ describe("The 'select' method", function () {
3737
3838 beforeEach ( function ( done ) {
3939 client = redis . createClient . apply ( redis . createClient , args ) ;
40- client . once ( "ready" , function ( ) { done ( ) ; } ) ;
40+ client . once ( "ready" , function ( ) {
41+ client . flushdb ( done ) ;
42+ } ) ;
4143 } ) ;
4244
4345 afterEach ( function ( ) {
@@ -46,7 +48,7 @@ describe("The 'select' method", function () {
4648
4749 it ( "changes the database and calls the callback" , function ( done ) {
4850 // default value of null means database 0 will be used.
49- assert . strictEqual ( client . selected_db , null , "default db should be null " ) ;
51+ assert . strictEqual ( client . selected_db , undefined , "default db should be undefined " ) ;
5052 var buffering = client . SELECT ( 1 , function ( err , res ) {
5153 helper . isNotError ( ) ( err , res ) ;
5254 assert . strictEqual ( client . selected_db , 1 , "db should be 1 after select" ) ;
@@ -58,7 +60,7 @@ describe("The 'select' method", function () {
5860 describe ( "and a callback is specified" , function ( ) {
5961 describe ( "with a valid db index" , function ( ) {
6062 it ( "selects the appropriate database" , function ( done ) {
61- assert . strictEqual ( client . selected_db , null , "default db should be null " ) ;
63+ assert . strictEqual ( client . selected_db , undefined , "default db should be undefined " ) ;
6264 client . select ( 1 , function ( err ) {
6365 assert . equal ( err , null ) ;
6466 assert . equal ( client . selected_db , 1 , "we should have selected the new valid DB" ) ;
@@ -69,7 +71,7 @@ describe("The 'select' method", function () {
6971
7072 describe ( "with an invalid db index" , function ( ) {
7173 it ( "returns an error" , function ( done ) {
72- assert . strictEqual ( client . selected_db , null , "default db should be null " ) ;
74+ assert . strictEqual ( client . selected_db , undefined , "default db should be undefined " ) ;
7375 client . select ( 9999 , function ( err ) {
7476 assert . equal ( err . code , 'ERR' ) ;
7577 assert . equal ( err . message , 'ERR invalid DB index' ) ;
@@ -82,7 +84,7 @@ describe("The 'select' method", function () {
8284 describe ( "and no callback is specified" , function ( ) {
8385 describe ( "with a valid db index" , function ( ) {
8486 it ( "selects the appropriate database" , function ( done ) {
85- assert . strictEqual ( client . selected_db , null , "default db should be null " ) ;
87+ assert . strictEqual ( client . selected_db , undefined , "default db should be undefined " ) ;
8688 client . select ( 1 ) ;
8789 setTimeout ( function ( ) {
8890 assert . equal ( client . selected_db , 1 , "we should have selected the new valid DB" ) ;
@@ -93,7 +95,7 @@ describe("The 'select' method", function () {
9395
9496 describe ( "with an invalid db index" , function ( ) {
9597 it ( "emits an error when callback not provided" , function ( done ) {
96- assert . strictEqual ( client . selected_db , null , "default db should be null " ) ;
98+ assert . strictEqual ( client . selected_db , undefined , "default db should be undefined " ) ;
9799
98100 client . on ( 'error' , function ( err ) {
99101 assert . strictEqual ( err . command , 'SELECT' ) ;
@@ -105,6 +107,21 @@ describe("The 'select' method", function () {
105107 } ) ;
106108 } ) ;
107109 } ) ;
110+
111+ describe ( "reconnection occurs" , function ( ) {
112+ it ( "selects the appropriate database after a reconnect" , function ( done ) {
113+ assert . strictEqual ( client . selected_db , undefined , "default db should be undefined" ) ;
114+ client . select ( 3 ) ;
115+ client . set ( 'foo' , 'bar' , function ( ) {
116+ client . stream . destroy ( ) ;
117+ } ) ;
118+ client . once ( 'ready' , function ( ) {
119+ assert . strictEqual ( client . selected_db , 3 ) ;
120+ assert ( typeof client . server_info . db3 === 'object' ) ;
121+ done ( ) ;
122+ } ) ;
123+ } ) ;
124+ } ) ;
108125 } ) ;
109126 } ) ;
110127 } ) ;
0 commit comments