1
1
'use strict' ;
2
2
3
3
var assert = require ( 'assert' ) ;
4
- var config = require ( ".. /lib/config" ) ;
5
- var helper = require ( '.. /helper' ) ;
4
+ var config = require ( "./lib/config" ) ;
5
+ var helper = require ( './helper' ) ;
6
6
var redis = config . redis ;
7
+ var zlib = require ( 'zlib' ) ;
7
8
var uuid = require ( 'uuid' ) ;
9
+ var client ;
8
10
9
11
describe ( "The 'multi' method" , function ( ) {
10
12
13
+ afterEach ( function ( ) {
14
+ client . end ( ) ;
15
+ } ) ;
16
+
17
+ describe ( 'regression test' , function ( ) {
18
+ it ( 'saved buffers with charsets different than utf-8 (issue #913)' , function ( done ) {
19
+ client = redis . createClient ( ) ;
20
+
21
+ var end = helper . callFuncAfter ( done , 100 ) ;
22
+
23
+ // Some random object created from http://beta.json-generator.com/
24
+ var test_obj = {
25
+ "_id" : "5642c4c33d4667c4a1fefd99" , "index" : 0 , "guid" : "5baf1f1c-7621-41e7-ae7a-f8c6f3199b0f" , "isActive" : true ,
26
+ "balance" : "$1,028.63" , "picture" : "http://placehold.it/32x32" , "age" : 31 , "eyeColor" : "green" , "name" : { "first" : "Shana" , "last" : "Long" } ,
27
+ "company" :
"MANGLO" , "email" :
"[email protected] " , "phone" :
"+1 (926) 405-3105" , "address" :
"747 Dank Court, Norfolk, Ohio, 1112" ,
28
+ "about" : "Eu pariatur in nisi occaecat enim qui consequat nostrud cupidatat id. " +
29
+ "Commodo commodo dolore esse irure minim quis deserunt anim laborum aute deserunt et est. Quis nisi laborum deserunt nisi quis." ,
30
+ "registered" : "Friday, April 18, 2014 9:56 AM" , "latitude" : "74.566613" , "longitude" : "-11.660432" , "tags" : [ 7 , "excepteur" ] ,
31
+ "range" : [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] , "friends" : [ 3 , { "id" : 1 , "name" : "Schultz Dyer" } ] ,
32
+ "greeting" : "Hello, Shana! You have 5 unread messages." , "favoriteFruit" : "strawberry"
33
+ } ;
34
+
35
+ function run ( ) {
36
+ if ( end ( ) === true ) {
37
+ return ;
38
+ }
39
+ // To demonstrate a big payload for hash set field values, let's create a big array
40
+ var test_arr = [ ] ;
41
+ for ( var i = 0 ; i < 80 ; i ++ ) {
42
+ var new_obj = JSON . parse ( JSON . stringify ( test_obj ) ) ;
43
+ test_arr . push ( new_obj ) ;
44
+ }
45
+
46
+ var json = JSON . stringify ( test_arr ) ;
47
+ zlib . deflate ( new Buffer ( json ) , function ( err , buffer ) {
48
+ if ( err ) {
49
+ done ( err ) ;
50
+ return ;
51
+ }
52
+
53
+ var multi = client . multi ( ) ;
54
+ multi . del ( 'SOME_KEY' ) ;
55
+
56
+ for ( i = 0 ; i < 100 ; i ++ ) {
57
+ multi . hset ( 'SOME_KEY' , 'SOME_FIELD' + i , buffer ) ;
58
+ }
59
+ multi . exec ( function ( err , res ) {
60
+ if ( err ) {
61
+ done ( err ) ;
62
+ return ;
63
+ }
64
+ run ( ) ;
65
+ } ) ;
66
+ } ) ;
67
+ }
68
+ run ( ) ;
69
+ } ) ;
70
+ } ) ;
71
+
11
72
helper . allTests ( function ( parser , ip , args ) {
12
73
13
74
describe ( "using " + parser + " and " + ip , function ( ) {
@@ -19,14 +80,13 @@ describe("The 'multi' method", function () {
19
80
} ) ;
20
81
21
82
describe ( "when not connected" , function ( ) {
22
- var client ;
23
83
24
84
beforeEach ( function ( done ) {
25
85
client = redis . createClient . apply ( redis . createClient , args ) ;
26
86
client . once ( "ready" , function ( ) {
27
87
client . quit ( ) ;
28
88
} ) ;
29
- client . on ( 'end' , function ( ) {
89
+ client . once ( 'end' , function ( ) {
30
90
return done ( ) ;
31
91
} ) ;
32
92
} ) ;
@@ -37,7 +97,7 @@ describe("The 'multi' method", function () {
37
97
assert ( err . message . match ( / T h e c o n n e c t i o n h a s a l r e a d y b e e n c l o s e d / ) ) ;
38
98
done ( ) ;
39
99
} ) ;
40
- assert . strictEqual ( notBuffering , false ) ;
100
+ assert . strictEqual ( notBuffering , true ) ;
41
101
} ) ;
42
102
43
103
it ( "reports an error if promisified" , function ( ) {
@@ -48,17 +108,12 @@ describe("The 'multi' method", function () {
48
108
} ) ;
49
109
50
110
describe ( "when connected" , function ( ) {
51
- var client ;
52
111
53
112
beforeEach ( function ( done ) {
54
113
client = redis . createClient . apply ( redis . createClient , args ) ;
55
114
client . once ( "connect" , done ) ;
56
115
} ) ;
57
116
58
- afterEach ( function ( ) {
59
- client . end ( ) ;
60
- } ) ;
61
-
62
117
it ( "executes a pipelined multi properly in combination with the offline queue" , function ( done ) {
63
118
var multi1 = client . multi ( ) ;
64
119
multi1 . set ( "m1" , "123" ) ;
@@ -93,11 +148,6 @@ describe("The 'multi' method", function () {
93
148
} ) ;
94
149
95
150
describe ( "when connection is broken" , function ( ) {
96
- var client ;
97
-
98
- afterEach ( function ( ) {
99
- client . end ( ) ;
100
- } ) ;
101
151
102
152
it ( "return an error even if connection is in broken mode if callback is present" , function ( done ) {
103
153
client = redis . createClient ( {
@@ -137,7 +187,6 @@ describe("The 'multi' method", function () {
137
187
} ) ;
138
188
139
189
describe ( "when ready" , function ( ) {
140
- var client ;
141
190
142
191
beforeEach ( function ( done ) {
143
192
client = redis . createClient . apply ( redis . createClient , args ) ;
@@ -148,10 +197,6 @@ describe("The 'multi' method", function () {
148
197
} ) ;
149
198
} ) ;
150
199
151
- afterEach ( function ( ) {
152
- client . end ( ) ;
153
- } ) ;
154
-
155
200
it ( "returns an empty result array" , function ( done ) {
156
201
var multi = client . multi ( ) ;
157
202
var notBuffering = multi . exec ( function ( err , res ) {
0 commit comments