-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiterator-scan-test.js
97 lines (73 loc) · 2.88 KB
/
iterator-scan-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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env node
/*
* Spade, SCAN iterator test.
*/
exports.test = function ( done, assertions ) {
var debug = !! true
, isArray = Array.isArray
, emptyFn = function () {}
, log = console.log
, dbg = debug ? console.log : emptyFn
, test_utils = require( './deps/test-utils' )
, inspect = test_utils.inspect
, format = test_utils.format
, Spade = require( '../' )
, client = Spade( {
security : {
'127.0.0.1:6379' : {
requirepass : ''
, db : -1
}
}
} )
// expected events
, evts = []
// collected events
, collected = client.logger.collected
, i = 0
// Spade default options for SCAN ZSCAN HSCAN commands.
, opt = {
match : '♠:key:*'
, count : 1
}
, n = 10
, cback = function ( err, data, iterate ) {
if ( ! data[ 0 ] ) return iter.next();
log( ' - check if last scan iteration returns an array: %s.', inspect( data[ 1 ]) );
assert.ok( isArray( data[ 1 ] ) );
log( '- check returned values form the last SCAN iteration,' );
log( '- iterations counter should be: %s < %s <= %s,', inspect( 0 ), inspect( data[ 2 ] ), inspect( n ) );
assert.ok( data[ 2 ] && ( data[ 2 ] <= n ) );
log( '- keys counter should be: %s,', inspect( n ) );
assert.ok( data[ 3 ] === n, 'got: ' + inspect( data[ 3 ] ) );
log( '- %s keys scanned through %s iterations.', inspect( data[ 3 ] ), inspect( data[ 2 ] ) );
log( '- now disconnecting client with QUIT.' );
client.commands.quit( function () {
log( '- OK, client was disconnected.' );
exit();
} );
}
, iter = null
, exit = typeof done === 'function' ? done : function () {}
, assert = assertions || require( 'assert' )
;
log( '- a new Spade client was created with default options:', inspect( client.options ) );
log( '- enable CLI logging.' );
client.cli( true, function ( ename, args ) {
dbg( ' !%s %s', ename, format( ename, args || [] ) );
}, true );
client.commands.flushdb();
log( '- SET %s keys for SCAN test.', inspect( n ) );
for ( i = 0; i < n; ++i ) client.commands.set( '♠:key:' + i, i );
log( '- load iterators.' );
client.loadIterators();
log( '- opening client connection.' );
client.connect( null, function () {
log( '- get a SCAN iterator with options: %s.', inspect( opt ) );
iter = client.iterators.scan( 0, opt, cback );
log( '- start iterations..' );
iter.next();
} );
};
// single test execution with node
if ( process.argv[ 1 ] === __filename ) exports.test = exports.test();