11'use strict' ;
22
33var 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' ) ;
66var redis = config . redis ;
7+ var zlib = require ( 'zlib' ) ;
78var uuid = require ( 'uuid' ) ;
9+ var client ;
810
911describe ( "The 'multi' method" , function ( ) {
1012
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+
1172 helper . allTests ( function ( parser , ip , args ) {
1273
1374 describe ( "using " + parser + " and " + ip , function ( ) {
@@ -19,14 +80,13 @@ describe("The 'multi' method", function () {
1980 } ) ;
2081
2182 describe ( "when not connected" , function ( ) {
22- var client ;
2383
2484 beforeEach ( function ( done ) {
2585 client = redis . createClient . apply ( redis . createClient , args ) ;
2686 client . once ( "ready" , function ( ) {
2787 client . quit ( ) ;
2888 } ) ;
29- client . on ( 'end' , function ( ) {
89+ client . once ( 'end' , function ( ) {
3090 return done ( ) ;
3191 } ) ;
3292 } ) ;
@@ -37,7 +97,7 @@ describe("The 'multi' method", function () {
3797 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 / ) ) ;
3898 done ( ) ;
3999 } ) ;
40- assert . strictEqual ( notBuffering , false ) ;
100+ assert . strictEqual ( notBuffering , true ) ;
41101 } ) ;
42102
43103 it ( "reports an error if promisified" , function ( ) {
@@ -48,17 +108,12 @@ describe("The 'multi' method", function () {
48108 } ) ;
49109
50110 describe ( "when connected" , function ( ) {
51- var client ;
52111
53112 beforeEach ( function ( done ) {
54113 client = redis . createClient . apply ( redis . createClient , args ) ;
55114 client . once ( "connect" , done ) ;
56115 } ) ;
57116
58- afterEach ( function ( ) {
59- client . end ( ) ;
60- } ) ;
61-
62117 it ( "executes a pipelined multi properly in combination with the offline queue" , function ( done ) {
63118 var multi1 = client . multi ( ) ;
64119 multi1 . set ( "m1" , "123" ) ;
@@ -93,11 +148,6 @@ describe("The 'multi' method", function () {
93148 } ) ;
94149
95150 describe ( "when connection is broken" , function ( ) {
96- var client ;
97-
98- afterEach ( function ( ) {
99- client . end ( ) ;
100- } ) ;
101151
102152 it ( "return an error even if connection is in broken mode if callback is present" , function ( done ) {
103153 client = redis . createClient ( {
@@ -137,7 +187,6 @@ describe("The 'multi' method", function () {
137187 } ) ;
138188
139189 describe ( "when ready" , function ( ) {
140- var client ;
141190
142191 beforeEach ( function ( done ) {
143192 client = redis . createClient . apply ( redis . createClient , args ) ;
@@ -148,10 +197,6 @@ describe("The 'multi' method", function () {
148197 } ) ;
149198 } ) ;
150199
151- afterEach ( function ( ) {
152- client . end ( ) ;
153- } ) ;
154-
155200 it ( "returns an empty result array" , function ( done ) {
156201 var multi = client . multi ( ) ;
157202 var notBuffering = multi . exec ( function ( err , res ) {
0 commit comments