@@ -37,7 +37,9 @@ describe("The 'select' method", function () {
37
37
38
38
beforeEach ( function ( done ) {
39
39
client = redis . createClient . apply ( redis . createClient , args ) ;
40
- client . once ( "ready" , function ( ) { done ( ) ; } ) ;
40
+ client . once ( "ready" , function ( ) {
41
+ client . flushdb ( done ) ;
42
+ } ) ;
41
43
} ) ;
42
44
43
45
afterEach ( function ( ) {
@@ -46,7 +48,7 @@ describe("The 'select' method", function () {
46
48
47
49
it ( "changes the database and calls the callback" , function ( done ) {
48
50
// 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 " ) ;
50
52
var buffering = client . SELECT ( 1 , function ( err , res ) {
51
53
helper . isNotError ( ) ( err , res ) ;
52
54
assert . strictEqual ( client . selected_db , 1 , "db should be 1 after select" ) ;
@@ -58,7 +60,7 @@ describe("The 'select' method", function () {
58
60
describe ( "and a callback is specified" , function ( ) {
59
61
describe ( "with a valid db index" , function ( ) {
60
62
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 " ) ;
62
64
client . select ( 1 , function ( err ) {
63
65
assert . equal ( err , null ) ;
64
66
assert . equal ( client . selected_db , 1 , "we should have selected the new valid DB" ) ;
@@ -69,7 +71,7 @@ describe("The 'select' method", function () {
69
71
70
72
describe ( "with an invalid db index" , function ( ) {
71
73
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 " ) ;
73
75
client . select ( 9999 , function ( err ) {
74
76
assert . equal ( err . code , 'ERR' ) ;
75
77
assert . equal ( err . message , 'ERR invalid DB index' ) ;
@@ -82,7 +84,7 @@ describe("The 'select' method", function () {
82
84
describe ( "and no callback is specified" , function ( ) {
83
85
describe ( "with a valid db index" , function ( ) {
84
86
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 " ) ;
86
88
client . select ( 1 ) ;
87
89
setTimeout ( function ( ) {
88
90
assert . equal ( client . selected_db , 1 , "we should have selected the new valid DB" ) ;
@@ -93,7 +95,7 @@ describe("The 'select' method", function () {
93
95
94
96
describe ( "with an invalid db index" , function ( ) {
95
97
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 " ) ;
97
99
98
100
client . on ( 'error' , function ( err ) {
99
101
assert . strictEqual ( err . command , 'SELECT' ) ;
@@ -105,6 +107,21 @@ describe("The 'select' method", function () {
105
107
} ) ;
106
108
} ) ;
107
109
} ) ;
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
+ } ) ;
108
125
} ) ;
109
126
} ) ;
110
127
} ) ;
0 commit comments