-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
50 lines (41 loc) · 1.81 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
const async = require('async');
const util = require('util');
Object.assign(util.inspect.defaultOptions, {depth: 5, colors: process.env.HEROKU ? false : true, compact: true});
const cli = require('redis').createClient(process.env.REDIS_URL);
const T = require('./nrq.js').create({options: {enclosure: true, debug: true, unsafe: true, redis: cli}});
// const T = require('./task.js');
let QUEUE = 'QTEST';
let TESTCASE = process.argv.slice(2)[0];
switch (TESTCASE) {
case 'listen': async.waterfall([
next => {
let resume = T.listen(QUEUE, {pause:true, visibility:10e3}, (e, r, tid) => {
if (e || !r) return;
console.log('pulled', r, tid);
// T.del(QUEUE, r._tid, (e,r) => console.log('del', e, r));
resume?.();
});
return next();
},
next => async.times(10, (n, next) => T.push(QUEUE, {date: new Date()}, (e, r) => next(e,r)), next),
(id, next) => T.len(QUEUE, (e, r) => next(e)),
next => setTimeout(next, 10e3),
next => async.times(10, (n, next) => T.push(QUEUE, {date: new Date()}, (e, r) => next(e,r)), next),
(id, next) => T.len(QUEUE, (e, r) => next(e)),
], e => {
})
break;
default: async.waterfall([
next => async.times(1e2, (n, next) => T.push(QUEUE, {date: new Date()}, (e, r) => next(e,r)), next),
(id, next) => T.len(QUEUE, (e, r) => next(e, id)),
(id, next) => T.pull(QUEUE, (e, r) => next(e, id)),
(id, next) => T.cpull(QUEUE, (e, r) => next(e, id)),
(id, next) => T.fpull(QUEUE, 1e3, (e, r) => next(e, id)),
(id, next) => T.lpull(QUEUE, {times: 30, interval: 200}, (e, r) => next(e, id)),
(id, next) => T.len(QUEUE, (e, r) => next(e, id)),
(id, next) => T.reset(QUEUE, id, (e, r) => next(e, id)),
(id, next) => T.len(QUEUE, (e, r) => next(e, id)),
(id, next) => T.flush(QUEUE, (e, r) => next(e, id)),
(id, next) => T.len(QUEUE, (e, r) => next(e, id)),
])
}