@@ -3,6 +3,7 @@ var config = require("../lib/config");
3
3
var nodeAssert = require ( "../lib/nodeify-assertions" ) ;
4
4
var redis = config . redis ;
5
5
var RedisProcess = require ( "../lib/redis-process" ) ;
6
+ var uuid = require ( "uuid" ) ;
6
7
7
8
describe ( "A node_redis client" , function ( ) {
8
9
@@ -20,97 +21,65 @@ describe("A node_redis client", function () {
20
21
describe ( "using " + parser + " and " + ip , function ( ) {
21
22
var client ;
22
23
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 ( ) ;
36
27
} ) ;
37
- } ) ;
38
- } ) ;
39
28
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 ) ;
42
32
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
+ } ) ;
50
39
} ) ;
51
40
} ) ;
52
41
53
- afterEach ( function ( ) {
54
- client . end ( ) ;
55
- } ) ;
42
+ describe ( "when connected" , function ( ) {
43
+ var client ;
56
44
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 ) ;
87
49
} ) ;
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 ( ) ;
94
52
} ) ;
95
53
} ) ;
96
54
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 ) {
102
61
client . on ( "reconnecting" , function on_recon ( params ) {
103
- client . on ( "ready " , function on_connect ( ) {
62
+ client . on ( "connect " , function on_connect ( ) {
104
63
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 ) ;
107
66
cb ( ) ;
108
67
} ) ;
109
68
} , function ( cb ) {
110
69
client . get ( "recon 1" , function ( err , res ) {
111
70
nodeAssert . isString ( "one" ) ( err , res ) ;
112
71
cb ( ) ;
113
72
} ) ;
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
+ } ) ;
114
83
} ] , function ( err , results ) {
115
84
client . removeListener ( "connect" , on_connect ) ;
116
85
client . removeListener ( "reconnecting" , on_recon ) ;
@@ -120,45 +89,79 @@ describe("A node_redis client", function () {
120
89
} ) ;
121
90
122
91
client . set ( "recon 1" , "one" ) ;
123
- client . subscribe ( "recon channel " , function ( err , res ) {
92
+ client . set ( "recon 2" , "two ", function ( err , res ) {
124
93
// Do not do this in normal programs. This is to simulate the server closing on us.
125
94
// For orderly shutdown in normal programs, do client.quit()
126
95
client . stream . destroy ( ) ;
127
96
} ) ;
128
97
} ) ;
129
98
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 ) ;
143
120
} ) ;
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
+ } ) ;
144
131
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 ) ;
151
156
} ) ;
152
- } ] , function ( err , results ) {
153
- done ( err ) ;
154
157
} ) ;
155
158
} ) ;
156
- } ) ;
157
159
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
+ } ) ;
162
165
} ) ;
163
166
} ) ;
164
167
} ) ;
0 commit comments