@@ -3,6 +3,7 @@ var config = require("../lib/config");
33var nodeAssert = require ( "../lib/nodeify-assertions" ) ;
44var redis = config . redis ;
55var RedisProcess = require ( "../lib/redis-process" ) ;
6+ var uuid = require ( "uuid" ) ;
67
78describe ( "A node_redis client" , function ( ) {
89
@@ -20,97 +21,65 @@ describe("A node_redis client", function () {
2021 describe ( "using " + parser + " and " + ip , function ( ) {
2122 var client ;
2223
23- after ( function ( ) {
24- client . end ( ) ;
25- } ) ;
26-
27- it ( "connects correctly" , function ( done ) {
28- client = redis . createClient . apply ( redis . createClient , args ) ;
29- client . on ( "error" , done ) ;
30-
31- client . once ( "ready" , function ( ) {
32- client . removeListener ( "error" , done ) ;
33- client . get ( "recon 1" , function ( err , res ) {
34- done ( err ) ;
35- } ) ;
24+ describe ( "when not connected" , function ( ) {
25+ afterEach ( function ( ) {
26+ client . end ( ) ;
3627 } ) ;
37- } ) ;
38- } ) ;
3928
40- describe ( "when connected" , function ( ) {
41- var client ;
29+ it ( "connects correctly" , function ( done ) {
30+ client = redis . createClient . apply ( redis . createClient , args ) ;
31+ client . on ( "error" , done ) ;
4232
43- beforeEach ( function ( done ) {
44- client = redis . createClient . apply ( redis . createClient , args ) ;
45- client . once ( "error" , function onError ( err ) {
46- done ( err ) ;
47- } ) ;
48- client . once ( "ready" , function onReady ( ) {
49- done ( ) ;
33+ client . once ( "ready" , function ( ) {
34+ client . removeListener ( "error" , done ) ;
35+ client . get ( "recon 1" , function ( err , res ) {
36+ done ( err ) ;
37+ } ) ;
38+ } ) ;
5039 } ) ;
5140 } ) ;
5241
53- afterEach ( function ( ) {
54- client . end ( ) ;
55- } ) ;
42+ describe ( "when connected" , function ( ) {
43+ var client ;
5644
57- describe ( "when redis closes unexpectedly" , function ( ) {
58- it ( "reconnects and can retrieve the pre-existing data" , function ( done ) {
59- client . on ( "reconnecting" , function on_recon ( params ) {
60- client . on ( "connect" , function on_connect ( ) {
61- async . parallel ( [ function ( cb ) {
62- client . get ( "recon 1" , function ( err , res ) {
63- nodeAssert . isString ( "one" ) ( err , res ) ;
64- cb ( ) ;
65- } ) ;
66- } , function ( cb ) {
67- client . get ( "recon 1" , function ( err , res ) {
68- nodeAssert . isString ( "one" ) ( err , res ) ;
69- cb ( ) ;
70- } ) ;
71- } , function ( cb ) {
72- client . get ( "recon 2" , function ( err , res ) {
73- nodeAssert . isString ( "two" ) ( err , res ) ;
74- cb ( ) ;
75- } ) ;
76- } , function ( cb ) {
77- client . get ( "recon 2" , function ( err , res ) {
78- nodeAssert . isString ( "two" ) ( err , res ) ;
79- cb ( ) ;
80- } ) ;
81- } ] , function ( err , results ) {
82- client . removeListener ( "connect" , on_connect ) ;
83- client . removeListener ( "reconnecting" , on_recon ) ;
84- done ( err ) ;
85- } ) ;
86- } ) ;
45+ beforeEach ( function ( done ) {
46+ client = redis . createClient . apply ( redis . createClient , args ) ;
47+ client . once ( "error" , function onError ( err ) {
48+ done ( err ) ;
8749 } ) ;
88-
89- client . set ( "recon 1" , "one" ) ;
90- client . set ( "recon 2" , "two" , function ( err , res ) {
91- // Do not do this in normal programs. This is to simulate the server closing on us.
92- // For orderly shutdown in normal programs, do client.quit()
93- client . stream . destroy ( ) ;
50+ client . once ( "ready" , function onReady ( ) {
51+ done ( ) ;
9452 } ) ;
9553 } ) ;
9654
97- describe ( "and it's subscribed to a channel" , function ( ) {
98- // reconnect_select_db_after_pubsub
99- // Does not pass.
100- // "Connection in subscriber mode, only subscriber commands may be used"
101- xit ( "reconnects, unsubscribes, and can retrieve the pre-existing data" , function ( done ) {
55+ afterEach ( function ( ) {
56+ client . end ( ) ;
57+ } ) ;
58+
59+ describe ( "when redis closes unexpectedly" , function ( ) {
60+ it ( "reconnects and can retrieve the pre-existing data" , function ( done ) {
10261 client . on ( "reconnecting" , function on_recon ( params ) {
103- client . on ( "ready " , function on_connect ( ) {
62+ client . on ( "connect " , function on_connect ( ) {
10463 async . parallel ( [ function ( cb ) {
105- client . unsubscribe ( "recon channel " , function ( err , res ) {
106- nodeAssert . isNotError ( ) ( err , res ) ;
64+ client . get ( "recon 1 " , function ( err , res ) {
65+ nodeAssert . isString ( "one" ) ( err , res ) ;
10766 cb ( ) ;
10867 } ) ;
10968 } , function ( cb ) {
11069 client . get ( "recon 1" , function ( err , res ) {
11170 nodeAssert . isString ( "one" ) ( err , res ) ;
11271 cb ( ) ;
11372 } ) ;
73+ } , function ( cb ) {
74+ client . get ( "recon 2" , function ( err , res ) {
75+ nodeAssert . isString ( "two" ) ( err , res ) ;
76+ cb ( ) ;
77+ } ) ;
78+ } , function ( cb ) {
79+ client . get ( "recon 2" , function ( err , res ) {
80+ nodeAssert . isString ( "two" ) ( err , res ) ;
81+ cb ( ) ;
82+ } ) ;
11483 } ] , function ( err , results ) {
11584 client . removeListener ( "connect" , on_connect ) ;
11685 client . removeListener ( "reconnecting" , on_recon ) ;
@@ -120,45 +89,79 @@ describe("A node_redis client", function () {
12089 } ) ;
12190
12291 client . set ( "recon 1" , "one" ) ;
123- client . subscribe ( "recon channel " , function ( err , res ) {
92+ client . set ( "recon 2" , "two ", function ( err , res ) {
12493 // Do not do this in normal programs. This is to simulate the server closing on us.
12594 // For orderly shutdown in normal programs, do client.quit()
12695 client . stream . destroy ( ) ;
12796 } ) ;
12897 } ) ;
12998
130- it ( "remains subscribed" , function ( ) {
131- var client2 = redis . createClient . apply ( redis . createClient , args ) ;
132-
133- client . on ( "reconnecting" , function on_recon ( params ) {
134- client . on ( "ready" , function on_connect ( ) {
135- async . parallel ( [ function ( cb ) {
136- client . on ( "message" , function ( channel , message ) {
137- try {
138- nodeAssert . isString ( "recon channel" ) ( null , channel ) ;
139- nodeAssert . isString ( "a test message" ) ( null , message ) ;
140- } catch ( err ) {
141- cb ( err ) ;
142- }
99+ describe ( "and it's subscribed to a channel" , function ( ) {
100+ // reconnect_select_db_after_pubsub
101+ // Does not pass.
102+ // "Connection in subscriber mode, only subscriber commands may be used"
103+ xit ( "reconnects, unsubscribes, and can retrieve the pre-existing data" , function ( done ) {
104+ client . on ( "reconnecting" , function on_recon ( params ) {
105+ client . on ( "ready" , function on_connect ( ) {
106+ async . parallel ( [ function ( cb ) {
107+ client . unsubscribe ( "recon channel" , function ( err , res ) {
108+ nodeAssert . isNotError ( ) ( err , res ) ;
109+ cb ( ) ;
110+ } ) ;
111+ } , function ( cb ) {
112+ client . get ( "recon 1" , function ( err , res ) {
113+ nodeAssert . isString ( "one" ) ( err , res ) ;
114+ cb ( ) ;
115+ } ) ;
116+ } ] , function ( err , results ) {
117+ client . removeListener ( "connect" , on_connect ) ;
118+ client . removeListener ( "reconnecting" , on_recon ) ;
119+ done ( err ) ;
143120 } ) ;
121+ } ) ;
122+ } ) ;
123+
124+ client . set ( "recon 1" , "one" ) ;
125+ client . subscribe ( "recon channel" , function ( err , res ) {
126+ // Do not do this in normal programs. This is to simulate the server closing on us.
127+ // For orderly shutdown in normal programs, do client.quit()
128+ client . stream . destroy ( ) ;
129+ } ) ;
130+ } ) ;
144131
145- client2 . subscribe ( "recon channel" , function ( err , res ) {
146- if ( err ) {
147- cb ( err ) ;
148- return ;
149- }
150- client2 . publish ( "recon channel" , "a test message" ) ;
132+ it ( "remains subscribed" , function ( ) {
133+ var client2 = redis . createClient . apply ( redis . createClient , args ) ;
134+
135+ client . on ( "reconnecting" , function on_recon ( params ) {
136+ client . on ( "ready" , function on_connect ( ) {
137+ async . parallel ( [ function ( cb ) {
138+ client . on ( "message" , function ( channel , message ) {
139+ try {
140+ nodeAssert . isString ( "recon channel" ) ( null , channel ) ;
141+ nodeAssert . isString ( "a test message" ) ( null , message ) ;
142+ } catch ( err ) {
143+ cb ( err ) ;
144+ }
145+ } ) ;
146+
147+ client2 . subscribe ( "recon channel" , function ( err , res ) {
148+ if ( err ) {
149+ cb ( err ) ;
150+ return ;
151+ }
152+ client2 . publish ( "recon channel" , "a test message" ) ;
153+ } ) ;
154+ } ] , function ( err , results ) {
155+ done ( err ) ;
151156 } ) ;
152- } ] , function ( err , results ) {
153- done ( err ) ;
154157 } ) ;
155158 } ) ;
156- } ) ;
157159
158- client . subscribe ( "recon channel" , function ( err , res ) {
159- // Do not do this in normal programs. This is to simulate the server closing on us.
160- // For orderly shutdown in normal programs, do client.quit()
161- client . stream . destroy ( ) ;
160+ client . subscribe ( "recon channel" , function ( err , res ) {
161+ // Do not do this in normal programs. This is to simulate the server closing on us.
162+ // For orderly shutdown in normal programs, do client.quit()
163+ client . stream . destroy ( ) ;
164+ } ) ;
162165 } ) ;
163166 } ) ;
164167 } ) ;
0 commit comments