-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.js
57 lines (42 loc) · 1.46 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var test = require('tape');
var redic = require('./index');
test('basic usage', function(t) {
t.plan(3);
var client = redic.connect(10001, 'localhost');
client.call('AUTH', 'test', function(err, res) {
t.assert(err === null, 'AUTH: OK');
client.call('SET', 'foo', 'bar', function(err, res) {
t.assert(res === 'OK', 'SET: OK');
client.call('GET', 'foo', function(err, res) {
t.assert(res === 'bar', 'GET: OK');
// Let's use the raw QUIT style here
// to try it out.
client.call('QUIT');
});
});
});
});
test('maxlisteners', function(t) {
t.plan(2);
// Empirical tests show that 1002 is the minimum you need
// to do a 1K loop below.
//
// If you change it to 1001 you'll get an error.
var client = redic.connect(10001, 'localhost', { maxListeners: 1002 });
client.call('AUTH', 'test', function(err, res) {
t.assert(err === null, 'AUTH: OK');
var total = 0;
var success = 0;
for (var i = 0; i < 1000; i++) {
client.call('PING', function(err) {
if (err === null) success++;
total++;
if (total === 1000) {
t.assert(success === 1000, '1000 PINGs: OK');
// We use the syntatic sugar `quit`.
client.quit();
}
});
}
});
});