memcache 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,238 +0,0 @@
1
- /*
2
- tests for expresso
3
- */
4
-
5
- var sys = require('sys'),
6
- memcache = require('memcache'),
7
- assert = require('assert'),
8
- port = 11211;
9
-
10
- mc = new memcache.Client(port);
11
- mc.on('error', function(e){
12
-
13
- if (e.errno == 111){
14
- exports['startup test'] = function(){
15
-
16
- assert.ok(false, "You need to have a memcache server running on localhost:11211 for these tests to run");
17
- }
18
- return;
19
- }
20
-
21
- exports['startup test'] = function(){
22
- assert.ok(false, "Unexpected error during connection: "+sys.inspect(e));
23
- }
24
- });
25
- mc.connect();
26
-
27
-
28
- mc.addHandler(function() {
29
-
30
- // test nonexistent key is null
31
- exports['test null value'] = function(beforeExit) {
32
- var n = 0;
33
- mc.get('no such key', function(err, r) {
34
- assert.equal(null, r);
35
- n++;
36
- });
37
-
38
- beforeExit(function() {
39
- assert.equal(1, n);
40
- });
41
- };
42
-
43
- // test set, get and expires
44
- exports['test set, get, and expires'] = function(beforeExit) {
45
- var n = 0;
46
- // set key
47
- mc.set('set1', 'asdf1', function() {
48
- n++;
49
- mc.get('set1', function(err, r) {
50
- // assert key is found
51
- assert.equal('asdf1', r);
52
- n++;
53
- // assert key expires after 1s
54
- setTimeout(function() {
55
- mc.get('set1', function(r) {
56
- mc.close();
57
- assert.equal(null, r);
58
- n++;
59
- });
60
- }, 1000);
61
- });
62
- }, 1);
63
-
64
- beforeExit(function() {
65
- assert.equal(3, n);
66
- });
67
- };
68
-
69
- exports['test set get with integer value'] = function(beforeExit) {
70
- mc.set('testKey', 123, function() {
71
- mc.get('testKey', function(err, r) {
72
- assert.equal(123,r);
73
- });
74
- });
75
- };
76
-
77
- // test set and delete
78
- exports['test set del'] = function(beforeExit) {
79
- var n = 0;
80
- // set key
81
- mc.set('set2', 'asdf2', function() {
82
- n++;
83
- mc.get('set2', function(err, r) {
84
- // assert key is found
85
- assert.equal('asdf2', r);
86
- n++;
87
- // delete key
88
- mc.delete('set2', function() {
89
- mc.get('set2', function(err, r) {
90
- // assert key is null
91
- assert.equal(null, r);
92
- n++;
93
- });
94
- });
95
- });
96
- }, 0);
97
-
98
- beforeExit(function() {
99
- assert.equal(3, n);
100
- });
101
- };
102
-
103
- // test utf8 handling
104
- exports['utf8'] = function(beforeExit) {
105
- mc.set('key1', 'привет', function() {
106
- mc.get('key1', function(err, r) {
107
- assert.equal('привет', r);
108
- });
109
- });
110
- };
111
-
112
-
113
- // test connecting and disconnecting
114
- exports['con disco'] = function(beforeExit) {
115
-
116
- var n = 0;
117
-
118
- var mc2 = new memcache.Client(port);
119
- mc2.on('connect', function(){
120
- n++;
121
- mc2.close();
122
- });
123
- mc2.on('close', function(){
124
- n++;
125
- });
126
-
127
- mc2.connect();
128
-
129
- beforeExit(function() {
130
- assert.equal(2, n);
131
- });
132
- };
133
-
134
- // increment / decrement
135
- exports['inc dec'] = function(beforeExit){
136
-
137
- var n = 0;
138
-
139
- mc.set('inc_bad', 'HELLO', function(err, response){
140
- assert.equal(response, 'STORED');
141
- n++;
142
- mc.increment('inc_bad', 2, function(err, ok){
143
- n++;
144
- assert.match(err, /^CLIENT_ERROR/);
145
- assert.equal(ok, null);
146
- });
147
- mc.decrement('inc_bad', 3, function(err, ok){
148
- n++;
149
- assert.match(err, /^CLIENT_ERROR/);
150
- assert.equal(ok, null);
151
- });
152
- mc.increment('inc_bad', null, function(err, ok){
153
- n++;
154
- assert.match(err, /^CLIENT_ERROR/);
155
- assert.equal(ok, null);
156
- });
157
- mc.decrement('inc_bad', null, function(err, ok){
158
- n++;
159
- assert.match(err, /^CLIENT_ERROR/);
160
- assert.equal(ok, null);
161
- });
162
- });
163
-
164
- mc.set('inc_good', '5', function(err, response){
165
- assert.equal(response, 'STORED');
166
- n++;
167
- mc.increment('inc_good', 2, function(err, response){
168
- n++;
169
- assert.equal(response, 7);
170
- mc.increment('inc_good', function(err, response){
171
- n++;
172
- assert.equal(response, 8);
173
- mc.decrement('inc_good', function(err, response){
174
- n++;
175
- assert.equal(response, 7);
176
- mc.decrement('inc_good', 4, function(err, response){
177
- n++;
178
- assert.equal(response, 3);
179
- });
180
- });
181
- });
182
- });
183
- });
184
-
185
- beforeExit(function(){
186
- assert.equal(10, n);
187
- });
188
-
189
- };
190
-
191
- exports['version'] = function(beforeExit){
192
- var n = 0;
193
-
194
- mc.version(function(error, success){
195
- n++;
196
- assert.equal(error, null);
197
- assert.length(success, 5);
198
- });
199
-
200
- beforeExit(function(){
201
- assert.equal(1, n);
202
- });
203
- };
204
-
205
- exports['stats'] = function(beforeExit){
206
- var n = 0;
207
-
208
- mc.stats(function(error, success){
209
- n++;
210
- assert.ok(success.pid, "server has a pid");
211
- });
212
-
213
- mc.stats('settings', function(error, success){
214
- n++;
215
- assert.ok(success.maxconns);
216
- });
217
-
218
- mc.stats('items', function(error, success){ n++; assert.ok(num_keys(success)); });
219
- mc.stats('sizes', function(error, success){ n++; assert.ok(num_keys(success)); });
220
- mc.stats('slabs', function(error, success){ n++; assert.ok(num_keys(success)); });
221
-
222
- mc.stats('notreal', function(error, success){
223
- n++;
224
- assert.equal(error, 'ERROR');
225
- });
226
-
227
- beforeExit(function(){
228
- assert.equal(6, n);
229
- });
230
- };
231
-
232
- });
233
-
234
- function num_keys(a){
235
- var i=0;
236
- for (var k in a) i++;
237
- return i;
238
- }