keuss 1.6.4 → 1.6.8
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.
- package/.nyc_output/ad035de4-a3d3-451b-b2ad-402e8ed517b8.json +1 -0
- package/.nyc_output/{06313f3e-1553-402b-bdc2-3a7a639cd559.json → c8683d6c-e7e6-496b-ab0d-1ff730837d08.json} +0 -0
- package/.nyc_output/processinfo/ad035de4-a3d3-451b-b2ad-402e8ed517b8.json +1 -0
- package/.nyc_output/processinfo/c8683d6c-e7e6-496b-ab0d-1ff730837d08.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/Pipeline/Queue.js +24 -1
- package/Queue.js +26 -10
- package/TODO +0 -7
- package/backends/bucket-mongo-safe.js +39 -3
- package/backends/mongo.js +23 -2
- package/backends/pl-mongo.js +2 -1
- package/backends/ps-mongo.js +31 -2
- package/backends/redis-oq.js +12 -1
- package/coverage/index.html +43 -43
- package/coverage/keuss/Pipeline/BaseLink.js.html +18 -18
- package/coverage/keuss/Pipeline/Builder.js.html +1 -1
- package/coverage/keuss/Pipeline/ChoiceLink.js.html +1 -1
- package/coverage/keuss/Pipeline/DirectLink.js.html +1 -1
- package/coverage/keuss/Pipeline/Pipeline.js.html +15 -15
- package/coverage/keuss/Pipeline/Queue.js.html +124 -55
- package/coverage/keuss/Pipeline/Sink.js.html +1 -1
- package/coverage/keuss/Pipeline/index.html +18 -18
- package/coverage/keuss/QFactory-MongoDB-defaults.js.html +6 -6
- package/coverage/keuss/QFactory.js.html +28 -28
- package/coverage/keuss/Queue.js.html +232 -181
- package/coverage/keuss/Signal.js.html +28 -28
- package/coverage/keuss/Stats.js.html +4 -4
- package/coverage/keuss/backends/bucket-mongo-safe.js.html +476 -314
- package/coverage/keuss/backends/bucket-mongo.js.html +134 -86
- package/coverage/keuss/backends/index.html +69 -69
- package/coverage/keuss/backends/mongo.js.html +137 -74
- package/coverage/keuss/backends/pl-mongo.js.html +54 -54
- package/coverage/keuss/backends/ps-mongo.js.html +164 -80
- package/coverage/keuss/backends/redis-list.js.html +39 -36
- package/coverage/keuss/backends/redis-oq.js.html +27 -27
- package/coverage/keuss/index.html +18 -18
- package/coverage/keuss/signal/index.html +1 -1
- package/coverage/keuss/signal/local.js.html +17 -17
- package/coverage/keuss/signal/mongo-capped.js.html +1 -1
- package/coverage/keuss/signal/redis-pubsub.js.html +12 -12
- package/coverage/keuss/stats/index.html +10 -10
- package/coverage/keuss/stats/mem.js.html +36 -30
- package/coverage/keuss/stats/mongo.js.html +8 -8
- package/coverage/keuss/stats/redis.js.html +17 -17
- package/coverage/keuss/utils/RedisConn.js.html +1 -1
- package/coverage/keuss/utils/RedisOrderedQueue.js.html +36 -33
- package/coverage/keuss/utils/index.html +5 -5
- package/docusaurus/docs/api/queue.md +24 -1
- package/docusaurus/docs/changelog.md +11 -0
- package/docusaurus/docs/concepts.md +13 -9
- package/docusaurus/package-lock.json +4422 -10244
- package/docusaurus/package.json +6 -6
- package/docusaurus/yarn.lock +8864 -0
- package/package.json +11 -11
- package/stats/mem.js +3 -1
- package/test/backends_bucket-at-least-once.js +13 -13
- package/test/backends_remove.js +299 -0
- package/test/backends_reserve-commit-rollback.js +165 -151
- package/utils/RedisOrderedQueue.js +46 -3
- package/.nyc_output/a06aa990-295d-4428-872d-ba9fa06afd1f.json +0 -1
- package/.nyc_output/processinfo/06313f3e-1553-402b-bdc2-3a7a639cd559.json +0 -1
- package/.nyc_output/processinfo/a06aa990-295d-4428-872d-ba9fa06afd1f.json +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keuss",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.8",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"queue",
|
|
6
6
|
"persistent",
|
|
@@ -26,19 +26,19 @@
|
|
|
26
26
|
},
|
|
27
27
|
"license": "GPL-3.0",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@nodebb/mubsub": "~1.
|
|
30
|
-
"async": "~3.2.
|
|
31
|
-
"async-lock": "~1.
|
|
32
|
-
"debug": "~4.
|
|
33
|
-
"ioredis": "~4.
|
|
29
|
+
"@nodebb/mubsub": "~1.7.1",
|
|
30
|
+
"async": "~3.2.1",
|
|
31
|
+
"async-lock": "~1.3.0",
|
|
32
|
+
"debug": "~4.3.2",
|
|
33
|
+
"ioredis": "~4.27.10",
|
|
34
34
|
"lodash": "~4.17.21",
|
|
35
|
-
"mitt": "~
|
|
36
|
-
"mongodb": "~3.
|
|
37
|
-
"uuid": "~8.3.
|
|
35
|
+
"mitt": "~3.0.0",
|
|
36
|
+
"mongodb": "~3.6.12",
|
|
37
|
+
"uuid": "~8.3.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"chance": "~1.1.
|
|
41
|
-
"mocha": "~
|
|
40
|
+
"chance": "~1.1.8",
|
|
41
|
+
"mocha": "~9.1.2",
|
|
42
42
|
"should": "~13.2.3"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
package/stats/mem.js
CHANGED
|
@@ -39,8 +39,10 @@ class MemStats extends Stats {
|
|
|
39
39
|
if (!this._s.counters[v]) {
|
|
40
40
|
this._s.counters[v] = 0;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
if ((delta == null) || (delta == undefined)) delta = 1;
|
|
44
|
+
var old_v = this._s.counters[v]
|
|
45
|
+
debug ('incr %s by %d: %d --> %d', v, delta, old_v, this._s.counters[v]);
|
|
44
46
|
this._s.counters[v] = this._s.counters[v] + delta;
|
|
45
47
|
if (cb) cb(null, this._s.counters[v]);
|
|
46
48
|
}
|
|
@@ -52,7 +52,7 @@ describe ('bucket-at-least-once with ' + MQ_item.label + ' queue backend', funct
|
|
|
52
52
|
function (cb) {q.totalSize (cb)},
|
|
53
53
|
function (cb) {q.next_t (cb)},
|
|
54
54
|
], function(err, results) {
|
|
55
|
-
results.should.eql ([{get: 0, put: 0}, 0, 0, null])
|
|
55
|
+
results.should.eql ([{get: 0, put: 0, reserve: 0, commit: 0, rollback: 0}, 0, 0, null])
|
|
56
56
|
done();
|
|
57
57
|
});
|
|
58
58
|
});
|
|
@@ -70,7 +70,7 @@ describe ('bucket-at-least-once with ' + MQ_item.label + ' queue backend', funct
|
|
|
70
70
|
cb();
|
|
71
71
|
})},
|
|
72
72
|
function (cb) {q.stats (function (err, res) {
|
|
73
|
-
res.should.eql ({get: 0, put: 2});
|
|
73
|
+
res.should.eql ({get: 0, put: 2, reserve: 0, commit: 0, rollback: 0});
|
|
74
74
|
cb();
|
|
75
75
|
})},
|
|
76
76
|
function (cb) {q.next_t (function (err, res) {
|
|
@@ -86,7 +86,7 @@ describe ('bucket-at-least-once with ' + MQ_item.label + ' queue backend', funct
|
|
|
86
86
|
cb();
|
|
87
87
|
})},
|
|
88
88
|
function (cb) {q.stats (function (err, res) {
|
|
89
|
-
res.should.eql ({get: 1, put: 2});
|
|
89
|
+
res.should.eql ({get: 1, put: 2, reserve: 0, commit: 0, rollback: 0});
|
|
90
90
|
cb();
|
|
91
91
|
})},
|
|
92
92
|
function (cb) {q.pop ('c2', function (err, ret) {
|
|
@@ -98,7 +98,7 @@ describe ('bucket-at-least-once with ' + MQ_item.label + ' queue backend', funct
|
|
|
98
98
|
cb();
|
|
99
99
|
})},
|
|
100
100
|
function (cb) {q.stats (function (err, res) {
|
|
101
|
-
res.should.eql ({get: 2, put: 2});
|
|
101
|
+
res.should.eql ({get: 2, put: 2, reserve: 0, commit: 0, rollback: 0});
|
|
102
102
|
cb();
|
|
103
103
|
})},
|
|
104
104
|
], function(err, results) {
|
|
@@ -139,7 +139,7 @@ describe ('bucket-at-least-once with ' + MQ_item.label + ' queue backend', funct
|
|
|
139
139
|
cb();
|
|
140
140
|
})},
|
|
141
141
|
function (cb) {q.stats (function (err, res) {
|
|
142
|
-
res.should.eql ({get: 2, put: 2});
|
|
142
|
+
res.should.eql ({get: 2, put: 2, reserve: 0, commit: 0, rollback: 0});
|
|
143
143
|
cb();
|
|
144
144
|
})},
|
|
145
145
|
], function(err, results) {
|
|
@@ -160,7 +160,7 @@ describe ('bucket-at-least-once with ' + MQ_item.label + ' queue backend', funct
|
|
|
160
160
|
(cb) => setTimeout (cb, 666),
|
|
161
161
|
|
|
162
162
|
(cb) => q.size ((err, size) => {size.should.equal (4); cb(); }),
|
|
163
|
-
(cb) => q.stats ((err, res) => {res.should.eql ({get: 0, put: 4}); cb(); }),
|
|
163
|
+
(cb) => q.stats ((err, res) => {res.should.eql ({get: 0, put: 4, reserve: 0, commit: 0, rollback: 0}); cb(); }),
|
|
164
164
|
|
|
165
165
|
(cb) => q.push ({elem:5, pl:'twetrwte'}, cb),
|
|
166
166
|
(cb) => q.push ({elem:6, pl:'twetrwte'}, cb),
|
|
@@ -168,7 +168,7 @@ describe ('bucket-at-least-once with ' + MQ_item.label + ' queue backend', funct
|
|
|
168
168
|
(cb) => setTimeout (cb, 666),
|
|
169
169
|
|
|
170
170
|
(cb) => q.size ((err, size) => {size.should.equal (7); cb(); }),
|
|
171
|
-
(cb) => q.stats ((err, res) => {res.should.eql ({get: 0, put: 7}); cb(); }),
|
|
171
|
+
(cb) => q.stats ((err, res) => {res.should.eql ({get: 0, put: 7, reserve: 0, commit: 0, rollback: 0}); cb(); }),
|
|
172
172
|
|
|
173
173
|
(cb) => q.next_t ((err, res) => {res.getTime().should.be.approximately(new Date().getTime(), 2000); cb(); }),
|
|
174
174
|
|
|
@@ -181,7 +181,7 @@ describe ('bucket-at-least-once with ' + MQ_item.label + ' queue backend', funct
|
|
|
181
181
|
(cb) => {q.pop ('c1', (err, ret) => {ret.payload.should.eql ({elem:7, pl:'twetrwte'}); cb (err); })},
|
|
182
182
|
|
|
183
183
|
(cb) => q.size ((err, size) => {size.should.equal (0); cb(); }),
|
|
184
|
-
(cb) => q.stats ((err, res) => {res.should.eql ({get: 7, put: 7}); cb(); }),
|
|
184
|
+
(cb) => q.stats ((err, res) => {res.should.eql ({get: 7, put: 7, reserve: 0, commit: 0, rollback: 0}); cb(); }),
|
|
185
185
|
], function(err, results) {
|
|
186
186
|
q.drain();
|
|
187
187
|
done();
|
|
@@ -211,7 +211,7 @@ describe ('bucket-at-least-once with ' + MQ_item.label + ' queue backend', funct
|
|
|
211
211
|
(cb) => q.size ((err, size) => {size.should.equal (0); cb(); }),
|
|
212
212
|
(cb) => q.totalSize ((err, size) => {size.should.equal (7); cb(); }),
|
|
213
213
|
(cb) => q.schedSize ((err, size) => {size.should.equal (7); cb(); }),
|
|
214
|
-
(cb) => q.stats ((err, res) => {res.should.eql ({get: 0, put: 7}); cb(); }),
|
|
214
|
+
(cb) => q.stats ((err, res) => {res.should.eql ({get: 0, put: 7, reserve: 0, commit: 0, rollback: 0}); cb(); }),
|
|
215
215
|
|
|
216
216
|
(cb) => {q.pop ('c1', (err, ret) => {ret.payload.should.eql ({elem:5, pl:'twetrwte'}); cb (err); })},
|
|
217
217
|
(cb) => {q.pop ('c1', (err, ret) => {ret.payload.should.eql ({elem:6, pl:'twetrwte'}); cb (err); })},
|
|
@@ -222,7 +222,7 @@ describe ('bucket-at-least-once with ' + MQ_item.label + ' queue backend', funct
|
|
|
222
222
|
(cb) => {q.pop ('c1', (err, ret) => {ret.payload.should.eql ({elem:4, pl:'twetrwte'}); cb (err); })},
|
|
223
223
|
|
|
224
224
|
(cb) => q.size ((err, size) => {size.should.equal (0); cb(); }),
|
|
225
|
-
(cb) => q.stats ((err, res) => {res.should.eql ({get: 7, put: 7}); cb(); }),
|
|
225
|
+
(cb) => q.stats ((err, res) => {res.should.eql ({get: 7, put: 7, reserve: 0, commit: 0, rollback: 0}); cb(); }),
|
|
226
226
|
], function(err, results) {
|
|
227
227
|
q.drain();
|
|
228
228
|
done();
|
|
@@ -239,13 +239,13 @@ describe ('bucket-at-least-once with ' + MQ_item.label + ' queue backend', funct
|
|
|
239
239
|
(cb) => setTimeout (cb, 700),
|
|
240
240
|
|
|
241
241
|
(cb) => q.size ((err, size) => {size.should.equal (2); cb(); }),
|
|
242
|
-
(cb) => q.stats ((err, res) => {res.should.eql ({get: 0, put: 2}); cb(); }),
|
|
242
|
+
(cb) => q.stats ((err, res) => {res.should.eql ({get: 0, put: 2, reserve: 0, commit: 0, rollback: 0}); cb(); }),
|
|
243
243
|
|
|
244
244
|
(cb) => q.push ({elem:3, pl:'twetrwte'}, cb),
|
|
245
245
|
(cb) => setTimeout (cb, 700),
|
|
246
246
|
|
|
247
247
|
(cb) => q.size ((err, size) => {size.should.equal (3); cb(); }),
|
|
248
|
-
(cb) => q.stats ((err, res) => {res.should.eql ({get: 0, put: 3}); cb(); }),
|
|
248
|
+
(cb) => q.stats ((err, res) => {res.should.eql ({get: 0, put: 3, reserve: 0, commit: 0, rollback: 0}); cb(); }),
|
|
249
249
|
|
|
250
250
|
(cb) => q.next_t ((err, res) => {res.getTime().should.be.approximately(new Date().getTime() - 1400, 100); cb(); }),
|
|
251
251
|
|
|
@@ -283,7 +283,7 @@ describe ('bucket-at-least-once with ' + MQ_item.label + ' queue backend', funct
|
|
|
283
283
|
(cb) => {q.pop ('c1', (err, ret) => {ret.payload.should.eql ({elem:1, pl:'twetrwte'}); cb (err); })},
|
|
284
284
|
|
|
285
285
|
(cb) => q.size ((err, size) => {size.should.equal (0); cb(); }),
|
|
286
|
-
(cb) => q.stats ((err, res) => {res.should.eql ({get:
|
|
286
|
+
(cb) => q.stats ((err, res) => {res.should.eql ({get: 3, put: 3, reserve: 2, commit: 0, rollback: 2}); cb(); }),
|
|
287
287
|
], function(err, results) {
|
|
288
288
|
q.drain();
|
|
289
289
|
done();
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
var async = require ('async');
|
|
2
|
+
var should = require ('should');
|
|
3
|
+
var _ = require ('lodash');
|
|
4
|
+
|
|
5
|
+
var LocalSignal = require ('../signal/local');
|
|
6
|
+
var MemStats = require ('../stats/mem');
|
|
7
|
+
|
|
8
|
+
const MongoClient = require ('mongodb').MongoClient;
|
|
9
|
+
const Redis = require("ioredis");
|
|
10
|
+
|
|
11
|
+
function stats (q, cb) {
|
|
12
|
+
async.series ({
|
|
13
|
+
stats: cb => q.stats(cb),
|
|
14
|
+
tsize: cb => q.totalSize(cb),
|
|
15
|
+
rsize: cb => q.resvSize(cb),
|
|
16
|
+
}, (err, res) => {
|
|
17
|
+
// console.log ('stats:', res);
|
|
18
|
+
cb (err, res);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function pop (q, stage, cb) {
|
|
23
|
+
q.pop('c1', { reserve: true }, (err, res) => {
|
|
24
|
+
stage.obj = res;
|
|
25
|
+
// console.log('reserved element %o', res);
|
|
26
|
+
cb(err);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function reject (q, stage, cb) {
|
|
31
|
+
var next_t = new Date().getTime() + 2000;
|
|
32
|
+
|
|
33
|
+
q.ko (stage.obj, next_t, (err, res) => {
|
|
34
|
+
if (err) {
|
|
35
|
+
// console.error ('error in rollback of %s: %j', stage.obj._id, err);
|
|
36
|
+
return cb (err);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// console.log('rolled back element %s: %o', stage.obj._id, res);
|
|
40
|
+
cb();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function accept (q, stage, cb) {
|
|
45
|
+
q.ok (stage.obj, (err, res) => {
|
|
46
|
+
if (err) {
|
|
47
|
+
// console.error ('error in rollback of %s: %j', stage.obj._id, err);
|
|
48
|
+
return cb (err);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// console.log('commited element %s: %j', stage.obj._id, res);
|
|
52
|
+
cb();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function get_mq_factory (MQ, opts, cb) {
|
|
57
|
+
const common_opts = {
|
|
58
|
+
url: 'mongodb://localhost/keuss_test_backends_remove',
|
|
59
|
+
signaller: { provider: LocalSignal},
|
|
60
|
+
stats: {provider: MemStats},
|
|
61
|
+
deadletter: {
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// initialize factory
|
|
66
|
+
MQ (_.merge ({}, common_opts, opts), cb);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function release_mq_factory (q, factory, cb) {
|
|
70
|
+
// console.log ('releasing mq factory');
|
|
71
|
+
|
|
72
|
+
setTimeout (() => {
|
|
73
|
+
q.cancel ();
|
|
74
|
+
factory.close (cb);
|
|
75
|
+
}, 1000);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
80
|
+
[
|
|
81
|
+
{label: 'Simple MongoDB', mq: require ('../backends/mongo')},
|
|
82
|
+
{label: 'Pipelined MongoDB', mq: require ('../backends/pl-mongo')},
|
|
83
|
+
{label: 'Tape MongoDB', mq: require ('../backends/ps-mongo')},
|
|
84
|
+
{label: 'Redis OrderedQueue', mq: require ('../backends/redis-oq')},
|
|
85
|
+
{label: 'MongoDB SafeBucket', mq: require ('../backends/bucket-mongo-safe')}
|
|
86
|
+
].forEach(function (MQ_item) {
|
|
87
|
+
var is_redis = (MQ_item.label == 'Redis OrderedQueue');
|
|
88
|
+
|
|
89
|
+
describe('remove operations on ' + MQ_item.label + ' queue backend', () => {
|
|
90
|
+
const MQ = MQ_item.mq;
|
|
91
|
+
|
|
92
|
+
beforeEach (done => {
|
|
93
|
+
done();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
afterEach (done => async.series ([
|
|
97
|
+
cb => setTimeout (cb, 1000),
|
|
98
|
+
cb => MongoClient.connect ('mongodb://localhost/keuss_test_backends_remove', (err, cl) => {
|
|
99
|
+
if (err) return done (err);
|
|
100
|
+
cl.db().dropDatabase (() => cl.close (cb))
|
|
101
|
+
}),
|
|
102
|
+
cb => {
|
|
103
|
+
const redis = new Redis();
|
|
104
|
+
redis.keys ('*', (err, keys) => {
|
|
105
|
+
const tasks = [];
|
|
106
|
+
_.each (keys, k => tasks.push (cb => redis.del (k, cb)));
|
|
107
|
+
async.series (tasks, (err, res) => {
|
|
108
|
+
redis.disconnect();
|
|
109
|
+
cb (err, res);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
], done));
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
it('fails on invalid id', done => {
|
|
117
|
+
// skip if redis
|
|
118
|
+
if (is_redis) return done();
|
|
119
|
+
|
|
120
|
+
async.waterfall ([
|
|
121
|
+
cb => get_mq_factory (MQ, {}, cb),
|
|
122
|
+
(factory, cb) => {
|
|
123
|
+
const q = factory.queue('test_queue_remove', {});
|
|
124
|
+
q.remove ('invalid-id', err => cb (null, err, q, factory))
|
|
125
|
+
},
|
|
126
|
+
(err, q, factory, cb) => {
|
|
127
|
+
err.should.match (/id \[invalid-id\] can not be used as remove id/);
|
|
128
|
+
release_mq_factory (q, factory, cb);
|
|
129
|
+
}
|
|
130
|
+
], done);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
it('fails on nonexistent id', done => {
|
|
135
|
+
async.waterfall ([
|
|
136
|
+
cb => get_mq_factory (MQ, {}, cb),
|
|
137
|
+
(factory, cb) => {
|
|
138
|
+
const q = factory.queue('test_queue_remove', {});
|
|
139
|
+
q.remove ('00112233445566778899aabb', (err, res) => cb (null, err, res, q, factory))
|
|
140
|
+
},
|
|
141
|
+
(err, res, q, factory, cb) => {
|
|
142
|
+
should (err).be.null();
|
|
143
|
+
res.should.be.false();
|
|
144
|
+
release_mq_factory (q, factory, cb);
|
|
145
|
+
}
|
|
146
|
+
], done);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
it('deletes regular element ok', done => {
|
|
151
|
+
const ctx = {};
|
|
152
|
+
async.waterfall ([
|
|
153
|
+
cb => get_mq_factory (MQ, {}, cb),
|
|
154
|
+
(factory, cb) => {
|
|
155
|
+
const q = factory.queue('test_queue_remove', {});
|
|
156
|
+
cb (null, q, factory);
|
|
157
|
+
},
|
|
158
|
+
(q, factory, cb) => async.series ([
|
|
159
|
+
cb => q.push ({a: 1, b: 'oo'}, cb),
|
|
160
|
+
cb => setTimeout (cb, 1000),
|
|
161
|
+
cb => stats (q, cb)
|
|
162
|
+
], (err, res) => {
|
|
163
|
+
ctx.id = res[0];
|
|
164
|
+
ctx.id.should.not.be.null();
|
|
165
|
+
res[2].should.eql ({
|
|
166
|
+
stats: { get: 0, put: 1, reserve: 0, commit: 0, rollback: 0 },
|
|
167
|
+
tsize: 1,
|
|
168
|
+
rsize: is_redis ? null : 0
|
|
169
|
+
})
|
|
170
|
+
cb (err, q, factory);
|
|
171
|
+
}),
|
|
172
|
+
(q, factory, cb) => {
|
|
173
|
+
q.remove (ctx.id, (err, res) => {
|
|
174
|
+
should (err).be.null();
|
|
175
|
+
res.should.be.true();
|
|
176
|
+
cb (err, q, factory);
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
(q, factory, cb) => async.series ([
|
|
180
|
+
cb => stats (q, cb),
|
|
181
|
+
cb => setTimeout (cb, 1000),
|
|
182
|
+
], (err, res) => {
|
|
183
|
+
res[0].should.eql ({
|
|
184
|
+
stats: { get: 0, put: 1, reserve: 0, commit: 0, rollback: 0 },
|
|
185
|
+
tsize: 0,
|
|
186
|
+
rsize: is_redis ? null : 0
|
|
187
|
+
});
|
|
188
|
+
cb (err, q, factory);
|
|
189
|
+
}),
|
|
190
|
+
(q, factory, cb) => {
|
|
191
|
+
release_mq_factory (q, factory, cb);
|
|
192
|
+
}
|
|
193
|
+
], done);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
it('does not delete reserved element', done => {
|
|
198
|
+
const ctx = {};
|
|
199
|
+
async.waterfall ([
|
|
200
|
+
cb => get_mq_factory (MQ, {}, cb),
|
|
201
|
+
(factory, cb) => {
|
|
202
|
+
const q = factory.queue('test_queue_remove', {});
|
|
203
|
+
cb (null, q, factory);
|
|
204
|
+
},
|
|
205
|
+
(q, factory, cb) => async.series ([
|
|
206
|
+
cb => q.push ({a: 1, b: 'oo'}, cb),
|
|
207
|
+
cb => setTimeout (cb, 1000),
|
|
208
|
+
], (err, res) => {
|
|
209
|
+
ctx.id = res[0];
|
|
210
|
+
ctx.id.should.not.be.null();
|
|
211
|
+
cb (err, q, factory);
|
|
212
|
+
}),
|
|
213
|
+
(q, factory, cb) => {
|
|
214
|
+
q.pop('c1', { reserve: true }, (err, res) => {
|
|
215
|
+
// res._id.should.eql (ctx.id);
|
|
216
|
+
cb (err, q, factory);
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
(q, factory, cb) => {
|
|
220
|
+
q.remove (ctx.id, (err, res) => {
|
|
221
|
+
should (err).be.null();
|
|
222
|
+
res.should.be.false();
|
|
223
|
+
cb (err, q, factory);
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
(q, factory, cb) => async.series ([
|
|
227
|
+
cb => stats (q, cb),
|
|
228
|
+
cb => setTimeout (cb, 1000),
|
|
229
|
+
], (err, res) => {
|
|
230
|
+
res[0].should.eql ({
|
|
231
|
+
stats: { get: 0, put: 1, reserve: 1, commit: 0, rollback: 0 },
|
|
232
|
+
tsize: 1,
|
|
233
|
+
rsize: is_redis ? null : 1
|
|
234
|
+
});
|
|
235
|
+
cb (err, q, factory);
|
|
236
|
+
}),
|
|
237
|
+
(q, factory, cb) => {
|
|
238
|
+
release_mq_factory (q, factory, cb);
|
|
239
|
+
}
|
|
240
|
+
], done);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
it('does delete reserved+rolledback element', done => {
|
|
245
|
+
const ctx = {};
|
|
246
|
+
async.waterfall ([
|
|
247
|
+
cb => get_mq_factory (MQ, {}, cb),
|
|
248
|
+
(factory, cb) => {
|
|
249
|
+
const q = factory.queue('test_queue_remove', {});
|
|
250
|
+
cb (null, q, factory);
|
|
251
|
+
},
|
|
252
|
+
(q, factory, cb) => async.series ([
|
|
253
|
+
cb => q.push ({a: 1, b: 'oo'}, cb),
|
|
254
|
+
cb => setTimeout (cb, 1000),
|
|
255
|
+
], (err, res) => {
|
|
256
|
+
ctx.id = res[0];
|
|
257
|
+
ctx.id.should.not.be.null();
|
|
258
|
+
cb (err, q, factory);
|
|
259
|
+
}),
|
|
260
|
+
(q, factory, cb) => {
|
|
261
|
+
q.pop('c1', { reserve: true }, (err, res) => {
|
|
262
|
+
res._id.should.eql (ctx.id);
|
|
263
|
+
cb (err, q, factory);
|
|
264
|
+
});
|
|
265
|
+
},
|
|
266
|
+
(q, factory, cb) => async.series ([
|
|
267
|
+
cb => q.ko(ctx.id, new Date().getTime() + 2000, cb),
|
|
268
|
+
cb => setTimeout (cb, 1000),
|
|
269
|
+
], (err, res) => {
|
|
270
|
+
res[0].should.be.true();
|
|
271
|
+
cb (err, q, factory);
|
|
272
|
+
}),
|
|
273
|
+
(q, factory, cb) => {
|
|
274
|
+
q.remove (ctx.id, (err, res) => {
|
|
275
|
+
should (err).be.null();
|
|
276
|
+
res.should.be.true();
|
|
277
|
+
cb (err, q, factory);
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
(q, factory, cb) => async.series ([
|
|
281
|
+
cb => stats (q, cb),
|
|
282
|
+
cb => setTimeout (cb, 1000),
|
|
283
|
+
], (err, res) => {
|
|
284
|
+
res[0].should.eql ({
|
|
285
|
+
stats: { get: 0, put: 1, reserve: 1, commit: 0, rollback: 1 },
|
|
286
|
+
tsize: 0,
|
|
287
|
+
rsize: is_redis ? null : 0
|
|
288
|
+
});
|
|
289
|
+
cb (err, q, factory);
|
|
290
|
+
}),
|
|
291
|
+
(q, factory, cb) => {
|
|
292
|
+
release_mq_factory (q, factory, cb);
|
|
293
|
+
}
|
|
294
|
+
], done);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
});
|
|
299
|
+
});
|